c# - 如何进行 Process.Start 阻塞调用?

标签 c# process blocking

我调用了运行第三方 exe 的 Process.Start()。我需要处理此可执行文件的输出文件,因此我希望阻塞对 Process.Start() 的调用。

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

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

最佳答案

Process.WaitForExit()正是您要找的。

Instructs the Process component to wait indefinitely for the associated process to exit.

你会像这样使用它:

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

关于c# - 如何进行 Process.Start 阻塞调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21394660/

相关文章:

c++ - 你将如何实现一个基本的事件循环?

c# - 检查两个数字中每个对应数字的总和是否相同?

c# - LINQ To SQL 忽略唯一约束异常并继续

wpf - 为什么 Process.WaitForInputIdle() 不起作用?

java - 如何检查可执行 JAR 是否已在另一个 JVM 中完成

c# - 无法加载可执行文件

java - 如何通过 http 序列化 msgpack

c# - 将-1转换为uint C#

java - 阻塞直到 ExecutorService 完成

c - 无法通过 C 中的套接字通过写入和读取函数发送 char 数组