简体   繁体   English

如何进行Process.Start阻止呼叫?

[英]How to make Process.Start a blocking call?

I have a call to Process.Start() which runs a third party exe. 我有一个运行第三方exe的Process.Start()调用。 I need to process the output files of this executable so I want the call to Process.Start() to be blocking. 我需要处理此可执行文件的输出文件,因此希望对Process.Start()的调用被阻止。

Is it possible to change this call to a blocking call? 可以将此呼叫更改为阻止呼叫吗?

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

Process.WaitForExit() is what you are looking for. 您正在寻找Process.WaitForExit()

Instructs the Process component to wait indefinitely for the associated process to exit. 指示流程组件无限期地等待关联的流程退出。

You would use it like this: 您可以这样使用它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM