Represents a pump that runs an asynchronous method and all its continuations on the current thread.
Some asynchronous methods expect that all its continuations are executed on the same thread. If such code needs to be run in an environment where this is not guaranteed (SynchronizationContext.Current is either null or is a SynchronizationContext object that schedules continuations on different threads as under ASP.NET) then this class can be used to force execution on a single thread.
Example #1
0
 public void MainTest()
 {
     AsyncPump.Run(
         async() =>
     {
         var counter = 0;
         var queue   = new TaskQueue();
         queue.Enqueue(
             async() =>
         {
             await Task.Delay(250);
             ++counter;
         }).Ignore();
         Assert.AreEqual(2, await queue.Enqueue(() => Task.FromResult(++counter)));
         Assert.AreEqual(2, counter);
     });
 }
 public void MainTest()
 {
     LogMethodPosition("Begin");
     AsyncPump.Run(DoEverything);
     LogMethodPosition("End");
 }