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

Gets or sets whether the System.Diagnostics.Process.Exited event is fired when the process terminates.

[Visual Basic]
Public Property WatchForExit As Boolean
[C#]
public bool WatchForExit {get; set;}
[C++]
public: __property bool get_WatchForExit();
public: __property void set_WatchForExit(bool);
[JScript]
public function get WatchForExit() : Boolean;
public function set WatchForExit(Boolean);

Property Value

true if the System.Diagnostics.Process.Exited event is fired when the associated process is terminated (either through an exit or a call to Kill); otherwise, false.

Remarks

WatchForExit indicates whether the component should be notified when the operating system has shut down a process. WatchForExit is used in asynchronous processing to notify your application that a process has exited. To make your application wait for an exit synchronously (which interrupts processing of the application until the exit event has occurred), use the WaitForExit method .

Note   If you are using Visiual Studio and double click on a Process component in your project, an System.Diagnostics.Process.Exited event handling delegate and event handling method are automatically generated. Another line sets the WatchForExit property to false. You must change this property to true in order for your event handling method to be executed when the associated process exits.

When an associated process exits (is shut down by the operation system either through a normal or abnormal termination), the operating system notifies any process component to which that process was associated, as long as the WatchForExit value for each component has been set to true. If the process was started by the component, the component can then access administrative information for the associated process, still being stored by the operating system. Such information includes ExitTime, and ExitCode.

After the associated process has exited, the Handle of the component no longer points to an existing process resource. Instead, it can just be used to access the operating system's information about the process resource. The operating system is aware there are handles to exited processes that have not been released by Process components, and keeps the ExitTime and Handle information in memory until the HandleCount is zero.

There is a cost associated with waiting for a process to exit. If WatchForExit is true, the System.Diagnostics.Process.Exited event is fired when the associated process terminates. The procedures that you have specified for the System.Diagnostics.Process.Exited event run at that time.

Sometimes your application can start a process and it is not important for you to be notified when of its closure. For example, your application can launch Notepad for the user to do text editing, but makes no further use of the application after it is launched. You can choose not to be notified when the process exits, because it is not relevant to the continued operation of your application. You can set WatchForExit to false to save system resources.

See Also

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