I am using Dispatcher
to switch to UI thread from external like this
Application.Current.Dispatcher.Invoke(myAction);
But I sa
The Dispatcher
class is useful when you’re sure that you are calling within the context of the user interface thread and the SynchronizationContext
is useful when you're not quite sure.
If you obtain your Dispatcher
class using the static Dispatcher.CurrentDispatcher
method on some non-UI thread and call the BeginInvoke
method, nothing will happen (No exception, no warning, nada).
However, if you obtain your SynchronizationContext
class via the static SynchronizationContext.Current
method, it will return null if the thread is not a UI thread. This feather is very useful because it allows you to react to both a UI thread and a non-UI thread accordingly.