Presuming you are using .NET 4.0, there is a bug where the System.Threading.SynchronizationContext.Current
on the main thread can become null, and you would experience this problem. If you can reproduce the problem easily, the first thing to check is if SynchronizationContext.Current
is null when you call TaskScheduler.FromCurrentSynchronizationContext()
.
See the details of that problem here: SynchronizationContext.Current is null in Continuation on the main UI thread
The bug is fixed in .NET 4.5.