In this paper, we describe the method of C # Implementing software to monitor the running state of external programs. Share to everyone for your reference. Here's how:
Need to plug a program to monitor another program running state, once detected another program shutdown, triggered an event to do other processing.
usingSystem.Diagnostics;//introducing the Process classPrivateprocess[] myprocesses; Myprocesses= Process.getprocessesbyname ("Sajetmanager");//The program name that needs to be monitored, this method takes out all the processes that the program usesforeach(Process myprocessinchmyprocesses) {TextBox1.Text+ = myprocess. ProcessName +"\ r \ n"; if(myprocess. Processname.tolower () = ="Sajetmanager") {MessageBox.Show ("Sajetmanager"); Myprocess. EnableRaisingEvents=true;//set the time to trigger when the process terminatesMyprocess. Exited + =NewEventHandler (myprocess_exited);//Discover external program shutdown is the trigger method myprocess_exited }} Private voidMyprocess_exited (Objectsender, EventArgs e)//programs that are triggered{MessageBox.Show ("Sajetmanager Close");}
C # implement software to monitor the running state of external programs