using System.Threading.Tasks;
using System.Collections.Generic;
public static void Main()
Console.WriteLine(SynchronizationContext.Current == null);
new Program().DoSomething().Wait();
public async Task DoSomething()
Console.WriteLine("Starting thread: " + Thread.CurrentThread.ManagedThreadId);
var listofProcessor = new List<Processor>{new Processor("Processor"), new Processor("Processor1")};
var tasks = listofProcessor.Select(x => x.Process());
Console.WriteLine("Before Task.WhenAll " + Thread.CurrentThread.ManagedThreadId);
await Task.WhenAll(tasks);
Console.WriteLine("After Task.WhenAll " + Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("Exception caught");
public Processor(string name)
public async Task<string> Process()
Console.WriteLine(_name + " BeforeAwait " + Thread.CurrentThread.ManagedThreadId);
Console.WriteLine(_name + " AfterAwait " + Thread.CurrentThread.ManagedThreadId);