How do you catch the "Exited" event when a process is terminated. In the following code sample the "myProcess_Exit ed" event is never called. Any help would be appreciated.
using System;
using System.Diagnost ics;
using System.Threadin g;
class ConsoleProcessA pp
{
public static void Main()
{
try
{
Process myProcess;
myProcess = Process.Start(" Notepad.exe");
myProcess.Exite d +=new EventHandler(my Process_Exited) ;
// Display physical memory usage.
// Discard cached information about the process.
myProcess.Refre sh();
// Print working set to console.
Console.WriteLi ne("Physical Memory Usage: " + myProcess.Worki ngSet.ToString( ));
// Close process by sending a close message to its main window.
myProcess.Close MainWindow();
// Free resources associated with process.
myProcess.Close ();
}
catch(Exception e)
{
Console.WriteLi ne("The following exception was raised: ");
Console.WriteLi ne(e.Message);
}
}
private static void myProcess_Exite d(object sender, EventArgs e)
{
Console.WriteLi ne("Event myProcess_Exite d has been called");
}
}
using System;
using System.Diagnost ics;
using System.Threadin g;
class ConsoleProcessA pp
{
public static void Main()
{
try
{
Process myProcess;
myProcess = Process.Start(" Notepad.exe");
myProcess.Exite d +=new EventHandler(my Process_Exited) ;
// Display physical memory usage.
// Discard cached information about the process.
myProcess.Refre sh();
// Print working set to console.
Console.WriteLi ne("Physical Memory Usage: " + myProcess.Worki ngSet.ToString( ));
// Close process by sending a close message to its main window.
myProcess.Close MainWindow();
// Free resources associated with process.
myProcess.Close ();
}
catch(Exception e)
{
Console.WriteLi ne("The following exception was raised: ");
Console.WriteLi ne(e.Message);
}
}
private static void myProcess_Exite d(object sender, EventArgs e)
{
Console.WriteLi ne("Event myProcess_Exite d has been called");
}
}
Comment