Example #1
0
        static async Task <int> MyMethodAsync()
        {
            // calling a 3rd party async void method
            var pump = new PumpingContext();
            var task = pump.Run(GetSomethingFromAService);
            await Task.WhenAll(task, pump.MainLoopTask);

            return(42);
        }
Example #2
0
        static async Task <int> MyMethodAsync()
        {
            // call an ill-designed 3rd party async void method
            // and await its completion
            var pump         = new PumpingContext();
            var startingTask = pump.Run(GetSomethingFromAService);
            await Task.WhenAll(startingTask, pump.CompletionTask);

            return(42);
        }
Example #3
0
 static async Task Main(string[] args)
 {
     try
     {
         var pump = new PumpingContext(CancellationToken.None);
         var task = pump.Run(MyMethodAsync, CancellationToken.None);
         await Task.WhenAll(task, pump.MainLoopTask);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }