如果我运行下面的代码:Process.Exited并不总是射击
Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "notepad.exe";
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new System.EventHandler(Process_OnExit);
myProcess.Start();
public static void Process_OnExit(object sender, EventArgs e)
{
// Delete the file on exit
}
,当我退出记事本事件引发。如果我尝试使用相同的代码,但是我开始使用相同的代码:
Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg";
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new System.EventHandler(Process_OnExit);
myProcess.Start();
public static void Process_OnExit(object sender, EventArgs e)
{
// Delete the file on exit
}
事件永远不会被解雇。是否因为加载图像的过程永远不会关闭?
UPDATE:开始该过程并不总是一个图像。它可以是任何东西(pdf,word文档等)。也许我的做法是不正确的。在用户退出过程之后是否有其他方式来删除文件?
谢谢
是的,我认为这是一个过程中的问题。Thx的帮助 – 2010-10-27 00:04:07