How to open a form in a thread and force it to stay open

前端 未结 6 1346
栀梦
栀梦 2021-01-02 10:40

I am still having problems with figuring out how to create winforms in a separate UI thread that I discussed here.

In trying to figure this out I wrote the following

6条回答
  •  长发绾君心
    2021-01-02 11:05

    You cannot open a GUI form in any thread, because it will be missing a message pump. You have to explicitly start a message pump in that thread by invoking Application.Run() in a thread method. Another option is to call a DoEvents() in a loop, if you need to do something else, because after Application.Run() that thread will wait a user to close a form in that point of execution.

提交回复
热议问题