I want to open a second program from my first program and still be able to work on my first program. And another thing is to close the second program from my first. Is there a way to do this?
-
What are you talking about? About managing opened solutions in Visual Studio? Or about launching another exe file from the program? – EngineerSpock Feb 28 '15 at 09:57
-
launching another exe file – Sean Goldfarb Feb 28 '15 at 10:03
3 Answers
For running the program:
You need using System.Diagnostics;
Process open_exe(string path)
{
Process to_open;
to_open.StartInfo.FileName = path;
to_open.Start();
return (to_open);
}
For closing the program:
void close_exe(Process p, bool force = false)
{
if(force)
{
p.Kill();
}
else
{
p.CloseMainWindow();
}
}
When calling open_exe
, it returns a Process
, which you can use in the close_exe
function as the argument.
Addition: on the close_exe
function, you can either call it by:
close_exe(process);
This will use the default value for force
as false
, and will not force it to close
close_exe(process, true);
This will not use the default value for force
, and use true
, and will thus force it to close

- 704
- 2
- 6
- 11
As to launching another exe-file see the following: codeproject, stackoverflow
As to closing the application I would say that the way to close the app depends on your needs. Two ways come to my mind immediately.
- The first is to ungracefully kill the exe as a process. You can kill any exe either by id or it's exe-name.
- The second one is to set up a communication between two processes with the help of WCF for interprocess communication.
You can easily google about killing processes in C# as well as about setting up a communication between two processes.

- 1
- 1

- 2,575
- 4
- 35
- 57
You can do it just for one line (with "using System.Diagnostics")
Process.Start(pathToAnotherProgramm);

- 67
- 4