Problems with dispatcher in C# console application

做~自己de王妃 提交于 2019-12-04 20:32:32

You need to actually start the dispatcher by calling Dispatcher.Run() for the dispatcher to process the calls invoked to it.

It's pretty strange to use a Dispatcher from a console application - the Dispatcher is used for WPF applications but I guess it will work.

Note that the call to Dispatcher.Run() won't return - it will enter a loop until you call Dispatcher.BeginInvokeShutdown()

See this blog post for an example.

Watsontap

Dispatcher.BeginInvoke uses the windows message pump. The thread to which you are trying to dispatch (processingThread) is not running a message pump.

You could run a message pump on that thread, but why would you do that instead of using an EventWaitHandle or some other thread sync object?

Also, the operations on the queue in your code are not thread safe.

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