Using SynchronizationContext for sending events back to the UI for WinForms or WPF

The immediate problem Your immediate problem is that SynchronizationContext.Current is not automatically set for WPF. To set it you will need to do something like this in your TheUISync code when running under WPF: var context = new DispatcherSynchronizationContext( Application.Current.Dispatcher); SynchronizationContext.SetSynchronizationContext(context); UISync = context; A deeper problem SynchronizationContext is tied in with the COM+ support … Read more

SynchronizationContext.Current is null in Continuation on the main UI thread

The issue is fixed in .NET 4.5 RC (just tested it). So I assume it is a bug in .NET 4.0. Also, I’m guessing that these posts are referencing the same issue: How can SynchronizationContext.Current of the main thread become null in a Windows Forms application? http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/629d5524-c8db-466f-bc27-0ced11b441ba That’s unfortunate. Now I have to consider workarounds. … Read more

Why the default SynchronizationContext is not captured in a Console App?

The word “capture” is too opaque, it sounds too much like that is something that the framework is supposed to. Misleading, since it normally does in a program that uses one of the default SynchronizationContext implementations. Like the one you get in a Winforms app. But when you write your own then the framework no … Read more