G
Guest
How do you catch the "Exited" event when a process is terminated. In the following code sample the "myProcess_Exited" event is never called. Any help would be appreciated.
using System;
using System.Diagnostics;
using System.Threading;
class ConsoleProcessApp
{
public static void Main()
{
try
{
Process myProcess;
myProcess = Process.Start("Notepad.exe");
myProcess.Exited +=new EventHandler(myProcess_Exited);
// Display physical memory usage.
// Discard cached information about the process.
myProcess.Refresh();
// Print working set to console.
Console.WriteLine("Physical Memory Usage: " + myProcess.WorkingSet.ToString());
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow();
// Free resources associated with process.
myProcess.Close();
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised: ");
Console.WriteLine(e.Message);
}
}
private static void myProcess_Exited(object sender, EventArgs e)
{
Console.WriteLine("Event myProcess_Exited has been called");
}
}
using System;
using System.Diagnostics;
using System.Threading;
class ConsoleProcessApp
{
public static void Main()
{
try
{
Process myProcess;
myProcess = Process.Start("Notepad.exe");
myProcess.Exited +=new EventHandler(myProcess_Exited);
// Display physical memory usage.
// Discard cached information about the process.
myProcess.Refresh();
// Print working set to console.
Console.WriteLine("Physical Memory Usage: " + myProcess.WorkingSet.ToString());
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow();
// Free resources associated with process.
myProcess.Close();
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised: ");
Console.WriteLine(e.Message);
}
}
private static void myProcess_Exited(object sender, EventArgs e)
{
Console.WriteLine("Event myProcess_Exited has been called");
}
}