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 (Int32)

Instructs the Process component to wait the specified number of milliseconds for the associated process to exit.

[Visual Basic]
Overloads Public Function WaitForExit( _
   ByVal milliseconds As Integer _
) As Boolean
[C#]
public bool WaitForExit(
   int milliseconds
);
[C++]
public: bool WaitForExit(
   int milliseconds
);
[JScript]
public function WaitForExit(
   milliseconds : int
) : Boolean;

Parameters

milliseconds
The amount of time, in milliseconds, to wait for the associated process to exit. The maximum is the largest possible value of a 32-bit integer, which represents infinity on the operating system.

Return Value

true if the associated process exited; otherwise, false.

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 a finite amount of time for the process to exit. If the associated process does not exit by the end of the interval because the request to terminate is denied, false is returned to the calling procedure. You can specify a negative number for milliseconds, but it is treated by WaitForExit as a very large positive number. If you pass in 0 to the method, it returns true only if the process has already exited.

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