NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Process.WaitForExit ()

Instructs the Process component to wait indefinitely for the associated process to exit.

[Visual Basic]
Overloads Public Sub WaitForExit()
[C#]
public void WaitForExit();
[C++]
public: void WaitForExit();
[JScript]
public function WaitForExit();

Exceptions

Exception Type Condition
Win32Exception The wait setting could not be accessed for the reason specified in the string. For example, the [give example] or [give another example].
SystemException No process Id has been set, and a Handle from which the Id can be determined does not exist.

-or-

There is no process associated with this Process object.

-or-

You are attempting to call WaitForExit on a process running on a remote computer. The method is only available for processes running on the local computer.

Remarks

WaitForExit is used in synchronous processing to notify your application that a process has exited. To allow your application to continue processing and be notified asynchronously that an System.Diagnostics.Process.Exited event has occurred, use the WaitForExit member and create an System.Diagnostics.Process.Exited event handling delegate and event handling method.

This overload of WaitForExit instructs the Process component to wait an infinite amount of time for the process to exit. This can cause an application to stop responding. For example, if you call CloseMainWindow on a Process that has a user interface, the request to the operating system to terminate the associated process may not be handled if the process is coded to never enter its message loop

When an associated process exits (is shut down by the operation system through either a normal or abnormal termination), the system stores information about the associated process and returns to the component that had called WaitForExit. The Process component can then access administrative information for the associated process stored by the operation system. Such information includes ExitTime, and is retrieved using the Handle to the now-exited process.

Because the associated process has exited, the handle that the process component has no longer points to an existing process resource. Instead, it can only be used 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 Process components, and keeps the ExitTime and Handle information in memory until the Process component specifically frees the resources. For this reason, any time you call Start on a Process, call Close when the associated process has terminated and you no longer need administrative information about it. Close frees the memory devoted to the exited process.

See Also

Process Class | Process Members | System.Diagnostics Namespace | Process.WaitForExit Overload List | CloseMainWindow | Kill | Handle | ExitTime | WatchForExit | System.Diagnostics.Process.Exited