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

前端 未结 6 1348
栀梦
栀梦 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:10

    Instead of calling show() on the form which will execute on the form and then just close at the end of the thread execution within function StartUiThread(), you can lock the thread until the form is stopped within the method as you are simply locking the other thread. Ex:

    public void StartUiThread() {
            _form = new Form1();
            _form.ShowDialog(); //Change Show() to ShowDialog() to wait in thread
        }
    

    This will cause the new thread to wait until the dialog is closed. I do not know if this will solve your problems, but it solved mine.

提交回复
热议问题