which thread does backgroundworker completed event handler run on?

本小妞迷上赌 提交于 2019-12-05 02:03:09

It's going to be run in the same thread that BackgroundWorker is in, ie most usually the UI thread.

is doSomethingElse going to be run on the main UI thread

Yes, that is the main reason of being for a Backgroundworker. It has 3 events, only DoWork will be executed on a separate (ThreadPool) thread. Completed and ProgressChanged will be marshaled to the 'main' thread.

mjcopple

If the BackgroundWorker was created from the UI thread, then the RunWorkerCompleted event will also be raised on the UI thread.

If it was created from a background thread, the event will be raised on an undefined background thread.

See this post and this connect issue for more information.

https://stackoverflow.com/a/2806824/279999

http://connect.microsoft.com/VisualStudio/feedback/details/116930/backgroundworker-components-progresschanged-and-runworkercompleted-event-run-on-wrong-thread

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