Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Timers;
  4.  
  5. namespace ConsoleApplication1
  6. {
  7. internal class Program
  8. {
  9. public static async Task Main(string[] args)
  10. {
  11. Console.WriteLine("Before await");
  12. await SomeAsyncCode();
  13. Console.WriteLine("After await");
  14. }
  15.  
  16. public static Task SomeAsyncCode()
  17. {
  18. var tcs = new TaskCompletionSource<bool>();
  19. var timer = new Timer();
  20.  
  21. timer.Interval = 5000;
  22. timer.Elapsed += (sender, args) => tcs.SetResult(true);
  23. timer.Enabled = true;
  24.  
  25. return tcs.Task;
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement