C# - 制作的Process.Start等到进程启动 [英] C# - Making a Process.Start wait until the process has start-up
本文介绍了C# - 制作的Process.Start等到进程启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要确保一个进程正在与一个方法之前运行。
I need to make sure that a process is running before moving on with a method.
的说法是:
Process.Start("popup.exe");
您可以做一个等待命令或设置这个值的延迟?
Can you do a WAIT command or set a delay on this value?
推荐答案
你的意思是等待,直到它完成?然后使用 Process.WaitForExit
:
Do you mean wait until it's done? Then use Process.WaitForExit
:
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "popup.exe"
}
};
process.Start();
process.WaitForExit();
另外,如果是与正在等待进入一个消息循环的UI的应用程序,你可以说:
Alternatively, if it's an application with a UI that you are waiting to enter into a message loop, you can say:
process.Start();
process.WaitForInputIdle();
最后,如果没有这些应用,只需 Thread.sleep代码
一段合理的时间内:
Lastly, if neither of these apply, just Thread.Sleep
for some reasonable amount of time:
process.Start();
Thread.Sleep(1000); // sleep for one second
这篇关于C# - 制作的Process.Start等到进程启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文