Advertisement
Guest User

Untitled

a guest
Oct 20th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1.         private async Task BeepAsync(int frequency)
  2.         {
  3.             await Task.Run(() => { Console.Beep(frequency, 100); });
  4.         }
  5.         private async Task PlayMelody(string melody, int timeout)
  6.         {
  7.             for (int i = 0; i < melody.Length; i++)
  8.             {
  9.                 switch (melody[i])
  10.                 {
  11.                     case 'A':
  12.                         await BeepAsync((int)Frequencies.A);
  13.                         await Task.Delay(1000);
  14.                         break;
  15.                     case 'B':
  16.                         await BeepAsync((int)Frequencies.B);
  17.                         await Task.Delay(1000);
  18.                         break;
  19.                     case 'C':
  20.                         await BeepAsync((int)Frequencies.C);
  21.                         await Task.Delay(1000);
  22.                         break;
  23.                     case 'D':
  24.                         await BeepAsync((int)Frequencies.D);
  25.                         await Task.Delay(1000);
  26.                         break;
  27.                     case 'E':
  28.                         await BeepAsync((int)Frequencies.E);
  29.                         await Task.Delay(1000);
  30.                         break;
  31.                     case 'F':
  32.                         await BeepAsync((int)Frequencies.F);
  33.                         await Task.Delay(1000);
  34.                         break;
  35.                     case 'G':
  36.                         await BeepAsync((int)Frequencies.G);
  37.                         await Task.Delay(1000);
  38.                         break;
  39.                     default:
  40.                         break;
  41.                 }
  42.             }
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement