Search code examples
c#winformsmultithreadingsynchronizationcontext

Why is SynchronizationContext.Current null in my Winforms application?


I just wrote this code:

System.Threading.SynchronizationContext.Current.Post(
    state => DoUpdateInUIThread((Abc)state), 
    abc);

but System.Threading.SynchronizationContext.Current is null


Solution

  • See this explanation.

    SynchronizationContext.Current is only set in the main thread (which is the only thread where you don't actually need it)

    The blog post proposes a workaround.