The Problem I am facing as my title suggests is determining if a program that I started using command lines has closed or ended.
I have tried many different ways in which to check if the program has exited, using process ID even using a loop, unfortunately I can’t seem to get it to work. I believe that it is due to the fact that I created a process which starts program using command lines rather than a method pointing to a directory to start the program. The reason I used command lines is that the path to the program is located in Program (x86), which wasn’t working for me due to the space I guess.
The part of the code that starts the application
ProcessStartInfo start = new ProcessStartInfo("cmd.exe", "/c cd / & /x & cd PROGRA~2 & cd Truvelo & cd DCM & start dcm.exe");
int exitCode;
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
exitCode = proc.ExitCode;
}
I did try something similar like this however I believe it didn’t work as I started the application using another process using command lines.
System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName(sProcessName);
if (proc.Length > 0)
{
MessageBox.Show(String.Format("{0}is running!", sProcessName), sProcessName);
}
else
{
MessageBox.Show(String.Format("{0}is not running!", sProcessName), sProcessName);
}
I am hoping someone can help me in a logical way to determine if I closed the application or for the code I am writing to know when the application is started and then tell me as soon as the application is closed
Thank you