为什么 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);