なぜ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 ..それはコードをブロックしないのですか? –
@MurHafSozアプリケーションが終了するまでコードを壁ブロックします。一度終了すると、コードは再び実行され始めます。 – JaredPar
だから私は 'while(true)'を保ち、単に 'break;'を追加しますか? –