The current BeginInvoke function in the DispatcherService causes the following error when accessing UI Elements with it:
"The calling thread must be STA, because many UI components require this."
I want to delegate functions asynchronous to the UI thread with the DispatcherService
but it's not possible because Action.BeginInvoke executes async on a threadpool thread.
It would be very helpful if you could add the above function which executes an action
only async if not on the same thread.
DispatcherService.cs: (this is the current version)
public void BeginInvoke(Action action)
var dispatcher = DispatcherHelper.CurrentDispatcher;
if (dispatcher != null && !dispatcher.CheckAccess())
dispatcher.InvokeAsync(CoreDispatcherPriority.Normal, (s, e) => action(), this, null);
// --------------------- this causes the error
action.BeginInvoke(null, null); // <<<--- should be also Invoke as above in the silverlight version