• 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. }  
  • 相关阅读:
    jquery 删除cookie失效的解决方法
    SQL Server 抛出自定义异常,由C#程序俘获之并进行相应的处理
    SqlServer中的自增的ID的最后的值:
    Stream/Bytes[]/Image对象相互转化
    TextBox禁止复制粘贴和数字验证,小数验证,汉字验证
    扩展WPF的DataGrid按方向键移动焦点
    WPF 中获取DataGrid 模板列中控件的对像
    IIS设置文件 App_Offline.htm 网站维护
    IIS设置文件 Robots.txt 禁止爬虫
    js中的整除运算
  • 原文地址:https://www.cnblogs.com/liushunli/p/5019728.html
Copyright © 2020-2023  润新知