How to run something in the STA thread?

后端 未结 5 1289
礼貌的吻别
礼貌的吻别 2020-11-29 03:17

In my WPF application I do some async communication (with server). In the callback function I end up creating InkPresenter objects from the result from server. This requires

5条回答
  •  醉酒成梦
    2020-11-29 04:00

    You can use the Dispatcher class to execute the method call on the UI-Thread. The Dispatcher provides the static property CurrentDispatcher to get the dispatcher of a thread.

    If your object of the class, that creates the InkPresenter, is created on the UI-Thread, then the CurrentDispatcher method returns the Dispatcher of the UI-Thread.

    On the Dispatcher you can call the BeginInvoke-method to call the specified delegate asynchronously on the thread.

提交回复
热议问题