我read該代碼的這一部分可能會導致死鎖:DeadLock Process.StandardOutput.ReadToEnd()中的問題;
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
因爲
死鎖條件可能會導致如果 父進程調用
p.WaitForExit
之前p.StandardOutput.ReadToEnd
和 子進程寫入足夠多的文本 來填充重定向的流。父進程 將無限期地等待 以使子進程退出。 子進程將無限期等待 ,父進程將從完整的 StandardOutput流中讀取。
但我不太清楚爲什麼。我的意思是,在這種情況下,父母的過程是什麼,孩子是什麼?
您可能對[此文章](http://www.codeducky.org/process-handling-net)感興趣,它解釋了使用.NET流程流的死鎖和其他複雜性。 – ChaseMedallion 2014-08-30 00:08:45