开发者

How to instantiate a Form while the main form is still responsive

开发者 https://www.devze.com 2023-03-03 01:28 出处:网络
I use .Net Framework 4.0 and C#. I want to dynamically instantiate a form in my code while the main form remains responsive. Is creating a new thread and call Application.Run(newForm) the only way of

I use .Net Framework 4.0 and C#. I want to dynamically instantiate a form in my code while the main form remains responsive. Is creating a new thread and call Application.Run(newForm) the only way of doing it? It just looks like a bit of a mess for such a simple thing. I thought it should be so common that the framework should have some kind of built-in functi开发者_如何学编程onality for this.


You don't need another thread to create a new form, and don't call Application.Run a second time. As long as you don't do anything that blocks the UI (and you never should), both forms will run just fine.

MyForm form = new MyForm();
form.Show();

If you call ShowDialog instead of Show from your first form, your first form will be blocked.

0

精彩评论

暂无评论...
验证码 换一张
取 消