- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Diagnostics;//引入Process 类
- namespace WhbServerTask
- {
- public partial class Form1 : Form
- {
- private string ExeName = "DOS_XXT";
- private string ExePath = @"E:\DOS_XXT.exe";
- private bool RunFlag = false;
- private Process[] MyProcesses;
- public Form1()
- {
- InitializeComponent();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- whbtask();
- } private void whbtask()
- {
- listBox1.Items.Add(DateTime.Now.ToString() + ": " + " 程序轮询,运行正常!");
- MyProcesses = Process.GetProcesses();
- foreach (Process MyProcess in MyProcesses)
- {
- //查找是否正在运行
- if (MyProcess.ProcessName.CompareTo(ExeName) == 0)
- {
- RunFlag = true;
- }
- }
- if (!RunFlag)//如果没有运行就启动
- {
- System.Diagnostics.Process.Start(ExePath);
- listBox1.Items.Add(DateTime.Now.ToString() + ": " + ExePath+" 程序重新启动一次!");
- }
- RunFlag = false;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- listBox1.Items.Clear();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- listBox1.Items.Add("说明:本程序为" + ExePath + "的运行监控程序,每1小时轮询一次,如果" + ExePath + "异
- 常关闭,则自动重启该程序!");
- }
- }
- }
时间: 2024-11-04 13:40:54