我现在写了一个监测一个程序运行的程序,当发现一个程序A终止时想让这个程序A自动重启,请问用C#应该怎样设置自动重启??主要程序代码是什么,谢谢了!!

解决方案 »

  1.   

    使用System.Diagnostics.Process放到timer控件里一直运行   if (System.Diagnostics.Process.GetProcessesByName("程序A").Length == 0)
                {
                    System.Diagnostics.Process.Start("程序A.exe");
                }
                
                
      

  2.   

    System.Diagnostics.Process.Start(Application.ExecutablePath); 
      

  3.   

    process.Exited += new EventHandler(Process_OnExit);
    void Process_OnExit(object sender, System.EventArgs e)
    {
                    Process curr  = (Process)sender;
                    curr.StartInfo.FileName = processPath;
                    curr.StartInfo.UseShellExecute = true;
                    curr.Start()
    }
      

  4.   

    processPath = process.MainModule.FileName;少写了一句话