This documentation is archived and is not being maintained.

Process.WaitForExit Method ()

.NET Framework 1.1

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

[Visual Basic]
Overloads Public Sub WaitForExit()
public void WaitForExit();
public: void WaitForExit();
public function WaitForExit();


Exception Type Condition
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.


There is no process associated with this Process object.


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


WaitForExit is used to make the current thread wait until the associated process terminates.

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 for a process that has a user interface, the request to the operating system to terminate the associated process might not be handled if the process is written to never enter its message loop.

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. 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.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

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