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. }  
  • 相关阅读:
    Redis
    多线程相关
    selenium操作浏览器的基本方法
    selenium之 webdriver与三大浏览器版本映射表(更新至v2.29)
    selenium安装及官方文档
    Python(3)_python对Json进行操作
    python类中的self参数和cls参数
    python3中shuffle函数
    Python3中assert断言
    python2和python3中range的区别
  • 原文地址:https://www.cnblogs.com/liushunli/p/5019728.html
Copyright © 2011-2022 走看看