[英]Reliability of Process.Start() then close current process by using C#
我有一个C#winform应用程序A,需要使用Process.Start启动另一个winform应用程序B,然后关闭自身。 源代码如下:
using(Process updater = new Process())
{
updater.StartInfo.FileName = "B.exe";
updater.Start();
}
this.Close();
但是我有时会注意到A关闭自身而不运行B。
我想知道如何在关闭A之前确保B.exe成功启动。
顺便说一句,我的目标框架应该是3.5&4。
提前致谢。
您可以检查该过程是否已启动并作出响应:
Boolean closeme = false;
using (System.Diagnostics.Process updater = new System.Diagnostics.Process())
{
updater.StartInfo.FileName = "B.exe";
if (updater.Start())
while (!updater.HasExited)
{
if (updater.Responding)
{
closeme = true;
break;
}
/* insert a timeout if process hangs */
}
if (updater.HasExited)
{
/* Do something else (updater.ExitCode) */
}
}
if (closeme)
this.Close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.