zoukankan      html  css  js  c++  java
  • c#监控程序

    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. }  
  • 相关阅读:
    光照模型
    多线程编程(7)Semaphore信号量
    多线程编程(3)
    Oracle SQL*plus常用的命令和函数
    经典的开发工具
    Windows 7/Vista下通过组策略禁止USB接口
    浅谈.NET下的多线程
    SQLServer和Oracle常用函数对比
    注册表操作类
    利用using和try/finally语句来清理资源
  • 原文地址:https://www.cnblogs.com/liushunli/p/5019728.html
Copyright © 2011-2022 走看看