Equivalent to InvokeRequired in WPF

前端 未结 4 1220
醉酒成梦
醉酒成梦 2021-02-15 22:40

Is there an equivalent to Form.InvokeRequired in WPF, e.g. Dispatcher.InvokeRequired?

4条回答
  •  情话喂你
    2021-02-15 23:33

    This is slightly odd as it doesn't appear in intellisense, but you can use:

    var dispatcher = myDispatcherObject.Dispatcher;
    if (dispatcher.CheckAccess()) { /* ... */ }
    

    As all UI components inherit from DispatcherObject this should solve your specific problem, but it is not specific to the UI thread - it can be used for any dispatcher.

提交回复
热议问题