Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Process.WaitForExit Method (Int32)

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

Namespace: System.Diagnostics
Assembly: System (in system.dll)

'Declaration
Public Function WaitForExit ( _
	milliseconds As Integer _
) As Boolean
'Usage
Dim instance As Process
Dim milliseconds As Integer
Dim returnValue As Boolean

returnValue = instance.WaitForExit(milliseconds)
public boolean WaitForExit (
	int milliseconds
)
public function WaitForExit (
	milliseconds : int
) : boolean
Not applicable.

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 to the operating system.

Return Value

true if the associated process has exited; otherwise, false.
Exception typeCondition

Win32Exception

The wait setting could not be accessed.

SystemException

No process Id has been set, and a Handle from which the Id property can be determined does not exist.

-or-

There is no process associated with this Process object.

-or-

You are attempting to call WaitForExit(Int32) for a process that is running on a remote computer. This method is available only for processes that are running on the local computer.

The WaitForExit(Int32) overload is used to make the current thread wait until the associated process terminates. This overload 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(Int32) as a very large positive number. If you pass 0 (zero) to the method, it returns true only if the process has already exited.

When standard output has been redirected to asynchronous event handlers, it is possible that output processing will not have completed when this method returns. To ensure that asynchronous event handling has been completed, call the WaitForExit overload that takes no parameter after receiving a true from this overload.

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

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

  • LinkDemand  for full trust for the immediate caller. This member cannot be used by partially trusted code.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.