Difference between Synchronization Context and Dispatcher

前端 未结 5 1011
孤独总比滥情好
孤独总比滥情好 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:49

    SynchronizationContext is an abstraction that uses virtual methods. Using SynchronizationContext allows you don't tie your implementation to a specific framework.

    Example: Windows Forms uses the WindowsFormSynchronizationContext that overrides Post to call Control.BeginInvoke. WPF uses the DispatcherSynchronizationContext type that overrides Post to call Dispatcher.BeginInvoke. You can design your component that uses SynchronizationContext and doesn't tie implementation to a particular framework.

提交回复
热议问题