我有一个应用程序
Process.Start()
启动另一个应用程序'ABC'。我想要等到应用程序结束(进程死亡)并继续执行。我该怎么做呢?
可能同时运行应用程序'ABC'的多个实例。
我有一个应用程序
Process.Start()
启动另一个应用程序'ABC'。我想要等到应用程序结束(进程死亡)并继续执行。我该怎么做呢?
可能同时运行应用程序'ABC'的多个实例。
当前回答
就像乔恩·斯基特说的,使用这个过程。退出:
proc.StartInfo.FileName = exportPath + @"\" + fileExe;
proc.Exited += new EventHandler(myProcess_Exited);
proc.Start();
inProcess = true;
while (inProcess)
{
proc.Refresh();
System.Threading.Thread.Sleep(10);
if (proc.HasExited)
{
inProcess = false;
}
}
private void myProcess_Exited(object sender, System.EventArgs e)
{
inProcess = false;
Console.WriteLine("Exit time: {0}\r\n" +
"Exit code: {1}\r\n", proc.ExitTime, proc.ExitCode);
}
其他回答
试试这个:
string command = "...";
var process = Process.Start(command);
process.WaitForExit();
使用Process.WaitForExit吗?或订阅进程。退出事件如果你不想阻止?如果这不能满足你的要求,请给我们更多的信息。
的过程。我认为WaitForExit应该正是你想要的。
我在我的申请中做了以下几点:
Process process = new Process();
process.StartInfo.FileName = executable;
process.StartInfo.Arguments = arguments;
process.StartInfo.ErrorDialog = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
process.Start();
process.WaitForExit(1000 * 60 * 5); // Wait up to five minutes.
有一些额外的功能,你可能会发现有用的…
你可以使用wait for exit或者你可以捕获HasExited属性并更新你的UI来让用户“被告知”(期望管理):
System.Diagnostics.Process process = System.Diagnostics.Process.Start("cmd.exe");
while (!process.HasExited)
{
//update UI
}
//done