Gets or sets whether the Process.Exited event should be raised when the process terminates.
Documentation for this section has not yet been entered.
The Process.EnableRaisingEvents property indicates whether the component should be notified when the operating system has shut down a process. The Process.EnableRaisingEvents property is used in asynchronous processing to notify your application that a process has exited. To force your application to synchronously wait for an exit event (which interrupts processing of the application until the exit event has occurred), use the Process.WaitForExit(int) method.
If you are using Visual Studio and double-click a System.Diagnostics.Process component in your project, an Process.Exited event delegate and event handler are automatically generated. Additional code sets the Process.EnableRaisingEvents property to false. You must change this property to true for your event handler to be executed when the associated process exits.
When an associated process exits after being shut down by the operating system either through a normal or abnormal termination, the operating system notifies each process component to which the process was associated, as long as the component's Process.EnableRaisingEvents value is true. If a component started the process, the component can then access the administrative information for the associated process, which is still being stored by the operating system. Such information includes the Process.ExitTime, and the Process.ExitCode.
After the associated process exits, the Process.Handle of the component no longer points to an existing process resource. Instead, it can be used only to access the operating system's information about the process resource. The operating system is aware that there are handles to exited processes that have not been released by System.Diagnostics.Process components, so it keeps the Process.ExitTime and Process.Handle information in memory.
There is a cost associated with watching for a process to exit. If Process.EnableRaisingEvents is true, the Process.Exited event is raised when the associated process terminates. The procedures that you have specified for the Process.Exited event run at that time.
Sometimes, your application starts a process but does not need to be notified of its closure. For example, your application can start Notepad to allow the user to perform text editing, but make no further use of the Notepad application. You can choose to not be notified when the process exits, because it is not relevant to the continued operation of your application. Setting Process.EnableRaisingEvents to false saves system resources.