的Visual C#GUI停止响应时process.WaitForExit();用来 [英] Visual C# GUI stops responding when process.WaitForExit(); is used

查看:1104
本文介绍了的Visual C#GUI停止响应时process.WaitForExit();用来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用Visual C#2005(.NET框架2)一个GUI应用程序。我用下面的代码来启动一个进程:

I am creating a GUI application using Visual C# 2005 (net framework 2). I use the following code to start a process:

Process process = new Process();
process.StartInfo = new ProcessStartInfo("app.exe");
process.StartInfo.WorkingDirectory = "";
process.StartInfo.Arguments = "some arguments";
process.Start();
process.WaitForExit();



我想我的应用程序要等到过程结束,所以我用WaitForExit。但是,GUI窗口,同时APP.EXE运行冻结。我希望它作出反应(如按下取消按钮),但我不希望代码继续,因为有另一个进程比后启动。在此先感谢!

I want my application to wait until this process is finished, so I used WaitForExit. But the GUI Windows freezes while app.exe is running. I want it to respond (e.g. press a cancel button), but I don't want the code to continue, because there is another process to start after than. Thanks in advance!

推荐答案

您可以捕捉的退出Process类的事件:

void someMethod()
{
    //...possibly more code here
    Process process = new Process();
    process.StartInfo = new ProcessStartInfo("app.exe");
    process.StartInfo.WorkingDirectory = "";
    process.StartInfo.Arguments = "some arguments";
    process.Exited += new EventHandler(ProcessExited);
    process.Start();
}

void ProcessExited(object sender, System.EventArgs e)
{
  //Handle process exit here
}

这篇关于的Visual C#GUI停止响应时process.WaitForExit();用来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆