Difference between Synchronization Context and Dispatcher

前端 未结 5 1016
孤独总比滥情好
孤独总比滥情好 2020-12-15 03:14

I am using Dispatcher to switch to UI thread from external like this

Application.Current.Dispatcher.Invoke(myAction);

But I sa

5条回答
  •  鱼传尺愫
    2020-12-15 03:50

    When using WPF, the SynchronizationContext.Current object is of type DispatcherSynchronizationContext which is actually just a wrapper around the Dispatcher object and the Post and Send methods just delegate to Dispatcher.BeginInvoke and Dispatcher.Invoke.

    So even if you decide to use SynchronizationContext I think you end up calling dispatcher behind the scenes.

    Besides I think it is a bit cumbersome to use SynchronizationContext as you have to pass a reference to the current context to all threads that need to call into your UI.

提交回复
热议问题