If I run the following code :
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
}
The event is raised when I exit notepad. If I try the same code, but I start an image instead :
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
}
The event is never fired. Is it because the process that loads the image is never closed ?
UPDATE : The process to start is not always an Image. It can be anything (pdf, word document, etc). Maybe my approach isn't right. Is there any other way to delete the file after the user exited the process ?
Thank you