C # software monitoring external program running status

Source: Internet
Author: User

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 ");}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.