SHARE
TWEET

Untitled

a guest Jul 12th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top