Creating a WinForm on the main thread using a backgroundworker

≡放荡痞女 提交于 2019-12-12 06:15:33

问题


I've got a background worker and I'm trying to get it to create an instance of a form, but I don't want the background worker thread to own the object, but would like the main thread to own it. Where do I start with this?


回答1:


You can use the Invoke and BeginInvoke functions to get the code to execute on the GUI thread. You could get your other thread to raise an event, then handle it in your main form, then your main form could invoke that call back onto its own thread (using InvokeRequired then Invoke) to launch the new form.

If you're using a background worker you may be able to put the OnProgressChanged method to use to signal back to your application to do something.

Also, take a look at this excellent book



来源:https://stackoverflow.com/questions/6315277/creating-a-winform-on-the-main-thread-using-a-backgroundworker

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