如果我運行下面的代碼: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