Why the Overhead for Multi Threaded Access to WPF UI controls?

后端 未结 3 810
灰色年华
灰色年华 2021-01-16 08:32

Have I missed something with WPF (and Windows Forms before it) in regards to the need to write a lot of repetitive code when developing multi-threaded applications. Every UI

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 08:56

    Don't forget lambdas:

    int myParam = 5;
    
    Dispatcher.BeginInvoke((Action)(() => SomeMethod(myParam)));
    

    There is also a hidden intellisense method on the dispatcher:

    if(Dispatcher.CheckAccess())
        DoSomething();
    

提交回复
热议问题