2 c# user-interface freeze waitforexit visual-studio
我正在使用Visual C#2005(net framework 2)创建一个GUI应用程序.我使用以下代码来启动一个过程:
Process process = new Process();
process.StartInfo = new ProcessStartInfo("app.exe");
process.StartInfo.WorkingDirectory = "";
process.StartInfo.Arguments = "some arguments";
process.Start();
process.WaitForExit();
Run Code Online (Sandbox Code Playgroud)
我希望我的应用程序等到这个过程结束,所以我使用了WaitForExit.但是,当app.exe运行时,GUI Windows会冻结.我希望它响应(例如按下取消按钮),但我不希望代码继续,因为还有另一个进程要启动.提前致谢!
您可以捕获Process类的Exited事件:
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
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9037 次 |
最近记录: |