简体   繁体   中英

Console and Windows Forms in C#

Ok I'm creating an application with a plugin architecture and the application would be able to run without a GUI in other words the GUI is really optional... and if the user decides to use the GUI the console is just hidden.

I can create the form in the console by calling one of the plugins method, but as soon the Window is created the console program keeps waiting until the window is closed... is there a way to create the form so that the console doesn't have to wait, it should keep working on it's own stuff and just notify the gui with some info?

Why don't you keep the windows forms application as a seperate executable and call process.start() ?

For example

Process.Start("c:\yourwindowsformsapplication.exe");

You can quit your console application or continue other work within the console application once you start the windowsapplication.exe.

And use remoting to communicate between both the applications.

or....

Create a new thread and call your form.show() within a new thread

Example :

Form frm=new form();
Thread th=new Thread(frm.show);
th.start();

Are you creating and then showing the form using ShowDialog()? If so, that's why the console app is waiting for the form to close. Try showing the form using Show() instead - Show() is a non-blocking call that will return program execution to the next line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM