Is there any way to use Dispatcher on a non WPF thread ; new to multi threading

穿精又带淫゛_ 提交于 2019-11-30 07:58:37

You don't call Dispatcher.Run. You're assuming that a Dispatcher contains a Thread that does its work, but this is backwards. The first time that Dispatcher.CurrentDispatcher is called, a Dispatcher is created bound to the current thread. Note that even though your code doesn't call CurrentDispatcher directly, it does do so indirectly by constructing a DispatcherObject (which captures CurrentDispatcher into a field).

Review the WPF threading model docs, which contain all the details you need.

If you want dispatcher-like functionality in a child thread but don't want to take a dependency on WPF, you can use the ActionThread class from Nito.Async, which is roughly equivalent to a Dispatcher plus a dedicated Thread.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!