Spawning form in new process

2019-09-13 21:12发布

I had originally created a windows form to be a dialog of my projects main form. Now the dialog is getting complex enough that it needs to be started in its own process. Is there a way to do this in code or do i need to create a new project and link my files to it?

2条回答
神经病院院长
2楼-- · 2019-09-13 21:23

You will need to set up a communication layer (WCF using named pipes would probably be the best way to go).

But I would seriously question why you need a new process for your form? Make sure that whatever work you do on your form is done on a separate thread. That way you can have dozens of forms open but your app will remain very responsive.

It's not the best solution, but if you are trying to avoid a rewrite, a call to Application.DoEvents will pump the message queue and get you some responsiveness back if you have a whole lot of updates happening on your UI. Band aid solution to your problem though.

查看更多
成全新的幸福
3楼-- · 2019-09-13 21:27

I question the premise here - there is no reason to necessarily start a new "form" in a separate process. If the form is getting that complex, however, I would recommend simplifying it, if for no reason other than usability.

That being said, you can always launch a new process via Process.Start in code. If you want it to be in the same project, but start a separate process, you could launch the executing exe with a command line argument that allows you to switch which "form" is loaded at startup.

查看更多
登录 后发表回答