C # Monitoring Program

Source: Internet
Author: User

  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.ComponentModel;
  4. Using System.Data;
  5. Using System.Drawing;
  6. Using System.Text;
  7. Using System.Windows.Forms;
  8. Using System.Diagnostics; //Introduce Process class
  9. Namespace Whbservertask
  10. {
  11. Public partial class Form1:form
  12. {
  13. private string exename = "Dos_xxt";
  14. private string exepath = @"E:\DOS_XXT.exe";
  15. private bool Runflag = false;
  16. private process[] myprocesses;
  17. Public Form1 ()
  18. {
  19. InitializeComponent ();
  20. }
  21. private void Timer1_Tick (object sender, EventArgs e)
  22. {
  23. Whbtask ();
  24. } private void Whbtask ()
  25. {
  26. LISTBOX1.ITEMS.ADD (DateTime.Now.ToString () + ":" + "program polling, running normally!   ");
  27. myprocesses = Process.getprocesses ();
  28. foreach (Process myprocess in myprocesses)
  29. {
  30. //Find out if it is running
  31. if (MyProcess.ProcessName.CompareTo (exename) = = 0)
  32. {
  33. Runflag = true;
  34. }
  35. }
  36. if (! Runflag)//start if not running
  37. {
  38. System.Diagnostics.Process.Start (ExePath);
  39. LISTBOX1.ITEMS.ADD (DateTime.Now.ToString () + ":" + exepath+"program restarts once!"   ");
  40. }
  41. Runflag = false;
  42. }
  43. private void button1_click (object sender, EventArgs e)
  44. {
  45. ListBox1.Items.Clear ();
  46. }
  47. private void Form1_Load (object sender, EventArgs e)
  48. {
  49. LISTBOX1.ITEMS.ADD ("description: This program for" + ExePath + "Running monitoring program, polling every 1 hours, if" + ExePath + "XOR
  50. The program is automatically restarted if it is always turned off! ");
  51. }
  52. }
  53. }

C # Monitoring Program

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.