c#監控程式

來源:互聯網
上載者: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;//引入Process 類   
  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() + ": " + " 程式輪詢,運行正常!");   
  27.             MyProcesses = Process.GetProcesses();   
  28.             foreach (Process MyProcess in MyProcesses)   
  29.             {                   
  30.                 //尋找是否正在運行   
  31.                 if (MyProcess.ProcessName.CompareTo(ExeName) == 0)   
  32.                 {   
  33.                     RunFlag = true;                       
  34.                 }                   
  35.             }   
  36.             if (!RunFlag)//如果沒有運行就啟動   
  37.             {   
  38.                 System.Diagnostics.Process.Start(ExePath);   
  39.                 listBox1.Items.Add(DateTime.Now.ToString() + ": " + ExePath+" 程式重新啟動一次!");   
  40.                    
  41.             }   
  42.             RunFlag = false;   
  43.               
  44.         }   
  45.         private void button1_Click(object sender, EventArgs e)   
  46.         {   
  47.             listBox1.Items.Clear();   
  48.         }   
  49.         private void Form1_Load(object sender, EventArgs e)   
  50.         {   
  51.             listBox1.Items.Add("說明:本程式為" + ExePath + "的運行監控程式,每1小時輪詢一次,如果" + ExePath + "異  
  52. 常關閉,則自動重啟該程式!");   
  53.         }   
  54.     }   
  55. }  

c#監控程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.