0

I have a console application and my first line is in the Main method is:

TaskScheduler.FromCurrentSynchronizationContext();

but here my application crashes with the System.InvalidOperationException : Additional information: The current SynchronizationContext may not be used as a TaskScheduler. I've searched on the MSDN, but I didn't found a documentation for this method. What have I done wrong?

Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
  • What's the current `SynchronizationContext`? – i3arnon Dec 05 '15 at 20:44
  • this was from the error message – Buda Gavril Dec 05 '15 at 21:31
  • But I think that I have this error because I have no UI thread in my console application, but I will have to do more research when I have time on this classes. – Buda Gavril Dec 05 '15 at 21:32
  • I meant what's the current `SynchronizationContext` as you can see in `SynchronizationContext.Current`. If it's `null`, which it is in a console app then you'll get this `InvalidOperationException`. – i3arnon Dec 05 '15 at 21:38
  • Well, then I'll have to make some research on how to synchronize my task on my console application. Indeed, SynchronizationContext.Current is null. – Buda Gavril Dec 05 '15 at 21:41

0 Answers0