【问题标题】:How to make Process.Start a blocking call?如何使 Process.Start 阻塞调用?
【发布时间】:2014-01-28 00:31:47
【问题描述】:

我打电话给Process.Start(),它运行第三方 exe。我需要处理这个可执行文件的输出文件,所以我希望对 Process.Start() 的调用被阻塞。

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

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

【问题讨论】:

    标签: c# process blocking


    【解决方案1】:

    Process.WaitForExit() 就是你要找的。​​p>

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

    你会这样使用它:

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

    【讨论】:

    • 一个简单的方法:Process process = Process.Start("explorer"); process.WaitForExit();
    • 是的,如果您不需要指定任何内容(将所有内容保留为默认值) - 那么您不需要 ProcessStartInfo 对象。我在这个答案中使用了一个,因为 OP 在他们的 sn-p 中使用了一个。
    猜你喜欢
    • 2013-11-16
    • 2020-09-01
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 2013-12-07
    • 2022-12-09
    • 2021-01-26
    • 1970-01-01
    相关资源
    最近更新 更多