Anonim_999

AsyncMenu

Sep 13th, 2022
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. Main main = new Main();
  2.  
  3. class Main
  4. {
  5.     private bool _isWorking = true;
  6.  
  7.     public Main()
  8.     {
  9.         Start();
  10.     }
  11.  
  12.     private void Menu()
  13.     {
  14.         while (_isWorking == false)
  15.         {
  16.             Console.WriteLine("1.Начать");
  17.             string userInput = Console.ReadLine();
  18.  
  19.             if (userInput == "1")
  20.             {
  21.                 _isWorking = true;
  22.                 Start();
  23.             }
  24.         }
  25.     }
  26.  
  27.     private async Task Start()
  28.     {
  29.         Task.Run(() => Write());
  30.  
  31.         while (_isWorking)
  32.         {
  33.             string userInput = Console.ReadLine();
  34.  
  35.             if (userInput == "1")
  36.             {
  37.                 _isWorking = false;
  38.             }
  39.         }
  40.         Menu();
  41.     }
  42.  
  43.     private async Task Write()
  44.     {
  45.         while (_isWorking)
  46.         {
  47.             Console.WriteLine("1.Действие");
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment