二个方法:以运行系统记事本为例
方法一:这种方法会阻塞当前进程,直到运行的外部程序退出
System.Diagnostics.Process exep = System.Diagnostics.Process.Start(@"C:\Windows\Notepad.exe"); exep.WaitForExit();//关键,等待外部程序退出后才能往下执行 MessageBox.Show("Notepad.exe运行完毕");
方法二:为外部进程添加一个事件监视器,当退出后,获取通知,这种方法时不会阻塞当前进程,你可以处理其它事情
System.Diagnostics.Process exep = new System.Diagnostics.Process(); exep.StartInfo.FileName = @"C:\Windows\Notepad.exe"; exep.EnableRaisingEvents = true; exep.Exited += new EventHandler(exep_Exited); exep.Start(); //exep_Exited事件处理代码,这里外部程序退出后激活,可以执行你要的操作 void exep_Exited(object sender, EventArgs e) { MessageBox.Show("Notepad.exe运行完毕"); }
来源:http://zhidao.baidu.com/link?url=u6hNAXaLxOYEcBIViascG2fgPRorVYQyN9eULCiVyNCKihlqUGJmCBOZWtp6KS8D71tFaCcrTnjt_xmQqqNNLa
C#如何判断程序调用的exe已结束
猜你喜欢
转载自blog.csdn.net/weixin_43442778/article/details/96649441
今日推荐
周排行