Process.WaitForExitAsync(CancellationToken) Method


Instructs the process component to wait for the associated process to exit, or for the cancellationToken to be cancelled.

public System.Threading.Tasks.Task WaitForExitAsync (System.Threading.CancellationToken cancellationToken = default);
member this.WaitForExitAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function WaitForExitAsync (Optional cancellationToken As CancellationToken = Nothing) As Task



An optional token to cancel the asynchronous operation.


A task that will complete when the process has exited, cancellation has been requested, or an error occurs.


The cancellation token was canceled. This exception is stored into the returned task.


Calling this method will set EnableRaisingEvents to true.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by WaitForExit().

Applies to