Guest User

Untitled

a guest
Jun 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. static async Task Main(string[] args)
  2. {
  3. await Task.Factory.StartNew(DisplayCurrentInfo);
  4. }
  5.  
  6. static async Task DisplayCurrentInfo()
  7. {
  8. await WaitAndApologize();
  9. Console.WriteLine($"The current time is {DateTime.Now.TimeOfDay:t}");
  10. Thread.Sleep(3000);
  11. }
  12.  
  13. static async Task Main(string[] args)
  14. {
  15. await DisplayCurrentInfo(); // or await Task.Run(DisplayCurrentInfo);
  16. }
  17.  
  18. static async Task DisplayCurrentInfo()
  19. {
  20. await WaitAndApologize();
  21. Console.WriteLine($"The current time is {DateTime.Now.TimeOfDay:t}");
  22. Thread.Sleep(3000);
  23. }
  24.  
  25. static async Task Main(string[] args)
  26. {
  27. await Task.Factory.StartNew(DisplayCurrentInfo);
  28. }
  29.  
  30. static async Task DisplayCurrentInfo()
  31. {
  32. WaitAndApologize();
  33. Console.WriteLine($"The current time is {DateTime.Now.TimeOfDay:t}");
  34. Thread.Sleep(3000);
  35. }
  36.  
  37. static async Task WaitAndApologize()
  38. {
  39. // Task.Delay is a placeholder for actual work.
  40. await Task.Delay(2000);
  41. // Task.Delay delays the following line by two seconds.
  42. Console.WriteLine("nSorry for the delay. . . .n");
  43. }
Add Comment
Please, Sign In to add comment