SoFunction
Updated on 2025-03-01

C# method to implement software monitoring the running status of external programs

This article describes the method of C# implementing software to monitor the running status of external programs. Share it for your reference. The specific methods are as follows:

An external program is required to monitor the running status of another program. Once another program is detected to be closed, an event will be triggered for other processing.

Referenced class

Copy the codeThe code is as follows:
using ;//Introduce Process class

statement

Copy the codeThe code is as follows:
private Process[] MyProcesses;

The main processing part, this code can be placed in the timer to loop to detect whether the monitored program is started.

Copy the codeThe code is as follows:
MyProcesses = ("SajetManager");//The program name that needs to be monitored, this method brings out all the processes used by the program
foreach (Process myprocess in MyProcesses)
{
    += + "\r\n";
    if (() == "sajetmanager")
    {
        ("SajetManager");
= true;//Set the time when the process terminates
+= new EventHandler(myprocess_Exited);//If the external program is closed, the method myprocess_Exited will be triggered.
    }
}
 
private void myprocess_Exited(object sender, EventArgs e)//The triggered program
{
    ("SajetManager close");
}

I hope this article will be helpful to everyone's C# programming.