我开始使用以下过程:
var process = Process.Start("somestuff.bat");
但是,当某些内容完成后,它不会终止进程,只会关闭窗口,所以很自然:
process.Exited += ...
永远不会开火。
那么,有没有办法以某种方式获取窗口句柄,或者process
的任何方便,并在该窗口关闭时触发方法?
答案 0 :(得分:1)
Use this make closing event..
XML Closing =" Window_Closing"
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgse)
{
KillProcess();
}
答案 1 :(得分:0)
您需要在流程上设置一些内容以使其触发事件
var process = Process.Start("somestuff.bat");
process.EnableRaisingEvents = true;
process.Exited += .. // note here, this runs in the process thread not the UI
退出然后开火
答案 2 :(得分:-1)
试试这可能会解决您的问题
foreach (var process in Process.GetProcessesByName(".exe"))
{
process.Kill();
}