System.Diagnostics.Process.Exited Event

Occurs when a process exits.

Syntax

[System.ComponentModel.Category("Behavior")]
[System.Diagnostics.MonitoringDescription("Raised when this process exits.")]
public event EventHandler Exited

Remarks

The Process.Exited event indicates that the associated process exited. This occurrence means either that the process terminated (aborted) or successfully closed. This event can occur only if the value of the Process.EnableRaisingEvents property is true.

There are two ways of being notified when the associated process exits: synchronously and asynchronously. Synchronous notification relies on calling the Process.WaitForExit(int) method to pause the processing of your application until the associated component exits. Asynchronous notification relies on the Process.Exited event. In either case, Process.EnableRaisingEvents must be set to true for the System.Diagnostics.Process component to receive notification that the process has exited.

When the operating system shuts down a process, any process component that is waiting for an exit is notified. The component can then access the associated process information that is still resident in the operating system memory (such as Process.ExitTime property) by using the handle that it has to the process.

Because the associated process has exited, the Process.Handle property 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 system is aware of handles to exited processes that have not been released by System.Diagnostics.Process components, so it keeps the Process.ExitTime and Process.Handle property information in memory until the System.Diagnostics.Process component specifically frees the resources.

Note:

Even if you have a handle to an exited process, you cannot call Process.Start again to reconnect to the same process. Calling Process.Start automatically releases the associated process and connects to a process with the same file but an entirely new Process.Handle.

For more information about the use of the Process.Exited event in Windows Forms applications, see the Process.SynchronizingObject property.

Requirements

Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0