2014-01-28 94 views
1

我打电话给Process.Start()运行第三方exe文件。我需要处理这个可执行文件的输出文件,所以我想调用Process.Start()来阻塞。如何使Process.Start阻止呼叫?

是否可以将此调用更改为阻塞调用?

Process sampleProcess= new Process(); 
sampleProcess.StartInfo = sampleProcessInfoObject; 
sampleProcess.Start(); 

回答

10

Process.WaitForExit()是你在找什么。

指示Process组件无限期地等待 相关联的过程退出。

你会使用这样的:

Process sampleProcess= new Process(); 
sampleProcess.StartInfo = sampleProcessInfoObject; 
sampleProcess.Start(); 
sampleProcess.WaitForExit(); // Will wait indefinitely until the process exits 
+1

一个简单的方法:'工艺过程=的Process.Start( “浏览器”); process.WaitForExit();' – Eliko

+0

是的,如果你不需要指定任何东西(把所有内容都默认) - 那么你不需要一个'ProcessStartInfo'对象。我在这个答案中使用了一个,因为OP在他们的片段中使用了一个。 –