今天看别人写的进程监护例子
class Program
{
static void Main(string[] args)
{
Process pro = new Process();
pro.StartInfo.FileName = "1";
pro.EnableRaisingEvents = true; //允许Exited事件
{
static void Main(string[] args)
{
Process pro = new Process();
pro.StartInfo.FileName = "1";
pro.EnableRaisingEvents = true; //允许Exited事件
pro.Exited += new EventHandler(pro_Exited);
pro.Start();
System.Threading.Thread.Sleep(-1);//永久等待
}
public static void run()
{
Process pro = new Process();
pro.StartInfo.FileName = "1";
pro.EnableRaisingEvents = true;
pro.Exited += new EventHandler(pro_Exited);//可以算是递归调用吧
pro.Start();
}
static void pro_Exited(object sender, EventArgs e)
{
run();
}
}