C# calling form.show() from another thread

后端 未结 4 1899
野性不改
野性不改 2020-12-16 10:48

if I call form.show() on a WinForms object from another thread, the form will throw an exception. Is where any way I can add a new, visible form to the main ap

4条回答
  •  盖世英雄少女心
    2020-12-16 11:33

    You should call Application.Run() after you call form.Show(). For example:

    public void showForm() 
    {
        // Do some work here.
        myForm form = new myForm();
        form.Text = "my text";
        form.Show();
        Application.Run();
        // Do some more work here
    }
    

    As for the details behind why, this msdn post may help.

提交回复
热议问题