The simplest way to start a process is to use the Start
static method of the Process
class:
Process.Start("yourapp.exe");
For access to more specific options, you can set up a ProcessStartInfo
object instead:
var startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "yourapp.exe";
startInfo.Arguments = "-arg1 val1";
var exeProcess = Process.Start(startInfo);
exeProcess.Start();
To check whether the process in question is still running, you can use this:
var matchingProcesses = Process.GetProcessesByName("yourapp");
var isRunning = matchingProcesses.Length > 0;
And you can put that in a method and poll every few seconds or milliseconds (depending on how fast you want to respond):
var aTimer = new Timer();
aTimer.Elapsed += new ElapsedEventHandler(YourMethod);
aTimer.Interval = 1000;
aTimer.Enabled = true;
These classes are found in the System.Diagnostics
and System.Timers
namespaces, respectively.