给你写一个基于 #3 楼那样的设计。假设你要守护的程序都写在一个文本文件 sc.ini 中,是这样的Name1=c:\\xxx\yyy\name1.exe Name2=d:\\mm.exe 其中,前边的是程序运行起来之后的进程名,后边是需要运行的程序的启动路径。你可以写这样一个 console 程序用来启动它们using System; using System.Diagnostics; using System.IO; using System.Linq;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sc.ini")); var sch = (from x in lines let s = x.Split('=') where s.Length == 2 select new { 进程名 = s[0].Trim(), 程序路径 = s[1].Trim() }).ToList(); sch.ForEach(sc => { var ps = Process.GetProcessesByName(sc.进程名); if (ps.Length == 0) Process.Start(sc.程序路径); }); } } }每次运行它,可以检查一遍目标程序启动状况。然后你就可以在你的服务器上创建一个 windows 计划任务,设置每隔10秒钟执行一次这个程序(这个程序很快,所以可以把间隔时间设置的短一些)。
你想在其他电脑上看?
可以先用winform程序监控进程,有问题写数据库,webform访问数据库
/// </summary>
/// <param name="hChild">子对象句柄</param>
/// <param name="hParent">父窗体句柄</param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SetParent(IntPtr hChild, IntPtr hParent);
Name2=d:\\mm.exe
其中,前边的是程序运行起来之后的进程名,后边是需要运行的程序的启动路径。你可以写这样一个 console 程序用来启动它们using System;
using System.Diagnostics;
using System.IO;
using System.Linq;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var lines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sc.ini"));
var sch = (from x in lines
let s = x.Split('=')
where s.Length == 2
select new
{
进程名 = s[0].Trim(),
程序路径 = s[1].Trim()
}).ToList();
sch.ForEach(sc =>
{
var ps = Process.GetProcessesByName(sc.进程名);
if (ps.Length == 0)
Process.Start(sc.程序路径);
});
}
}
}每次运行它,可以检查一遍目标程序启动状况。然后你就可以在你的服务器上创建一个 windows 计划任务,设置每隔10秒钟执行一次这个程序(这个程序很快,所以可以把间隔时间设置的短一些)。