lets say I have a process with the ID 1234. This process is running before my application runs.
I have this code:
Process app = Process.GetProcessById(1234);
MessageBox.Show(app.MainWindowTitle);
app.Exited += this.methodShowsMessageBox;
Now, when I compile and run the app, it gets the process and shows the main window title. However when i close process 1234, the app.Exited does nto fire... why is this? And how would i get it to fire?
By default, for performance reasons, the Process class does not raise events. If you want the Process object to watch for Exited and raise that event, you need to set its EnableRaisingEvents property to true.
Please note that the documentation states that
EnableRaisingEvents
must be set totrue
before this event will fire.