Invoking a UI thread from a worker thread is discussed lot of times and we know why to use BeginInvoke() instead of Invoke(). I recently posted this question and after doing some research I found out that there are at least three different ways (internally they might be same) to invoke (asynchronously) something on UI thread.
Control.BeginInvoke()
- Using
SynchronizatoinContext
Class - Using
Dispatcher.BeginInvoke(priority.. )
Can anyone tell me which is a RELIABLE way to asynchronously call a method to be executed on UI thread. Any experience ? I see Dispatcher.BeginInvoke has priority component to it, does it make it more reliable ?
Context:
we are using someControl.BeginInvoke()
but noticed that sometimes (unfortunately only in the end user production environment) the delegate passed to BeginInvoke is
never executed which makes me believe that the post message which it creates is getting lost. We want a reliable way to communicate back to the UI thread. control.Invoke()
sometimes hang the UI so we don't want to go there either.