C # software monitoring external program running status
You need to plug-in a program to monitor the status of another program. Once another program is detected to be closed, an event is triggered for other processing.
Referenced class
Using System. Diagnostics; // introduce the Process class
Statement
private Process[] MyProcesses;
The main processing part is that the code can be placed in the timer to check whether the Monitored Program is started cyclically.
MyProcesses = Process. getProcessesByName ("SajetManager"); // the name of the program to be monitored. This method takes out all processes used by the program, foreach (Process myprocess in MyProcesses) {textBox1.Text + = myprocess. processName + "\ r \ n"; if (myprocess. processName. toLower () = "sajetmanager") {MessageBox. show ("SajetManager"); myprocess. enableRaisingEvents = true; // set the time when the process is terminated. myprocess. exited + = new EventHandler (myprocess_Exited); // trigger method myprocess_Exited when an external program is disabled }}
Private void myprocess_Exited (object sender, EventArgs e) // The triggered program {MessageBox. Show ("SajetManager close ");}