爲什麼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