为什么Process.WaitForExit不会等待?为什么Process.WaitForExit不会等待?
static void Main(string[] args)
{
while (true)
{
try
{
if (Process.GetProcessesByName("ServerAPPFileManager").Length > 0)
{
Process clsProcess = Process.GetProcessesByName("ServerAPPFileManager")[0];
Console.WriteLine(clsProcess.ProcessName);
clsProcess.WaitForExit();
}
if (System.IO.File.Exists(System.IO.Path.Combine(Environment.CurrentDirectory, "ServerAPPFileManager.exe")))
{
Console.WriteLine("File Found");
Process p = new Process();
p.StartInfo.Verb = "runas";
p.StartInfo.FileName = System.IO.Path.Combine(Environment.CurrentDirectory, "ServerAPPFileManager.exe");
p.Start();
}
}
catch(Exception e)
{
Console.Write(e.Message);
System.Threading.Thread.Sleep(1000);
}
}
}
它保持循环,并一次又一次地启动应用程序!
编辑:
现在的工作,这是行不通的,因为它是这样clsProcess.WaitForExit(1000);
但是WaitForExist怎么样?是不是会阻塞代码? – 2012-04-12 14:29:28
@MurHafSoz它墙上的代码,直到应用程序退出。一旦它退出代码将再次开始运行 – JaredPar 2012-04-12 14:30:35
所以我保留'while(true)'并且只是添加一个'break;'? – 2012-04-12 14:32:42