Skip to content

Question: Do you need to call Process.WaitForExit() after Process.WaitForExitAsync(CancellationToken) #34294

@meziantou

Description

@meziantou

In .NET you should call Process.WaitForExit() to ensures that all processing has been completed, including the handling of asynchronous events for redirected standard output.

Process p = Process.Start(...);
while (!p.WaitForExit(1000)) {}

// call WaitForExit() here to ensures that all processing has been completed
p.WaitForExit();

In .NET 5 there is a new method Process.WaitForExitAsync(CancellationToken). Should we call WaitForExit after Process.WaitForExitAsync?

Process p = Process.Start(...);
await p.WaitForExitAsync(cancellationToken);

// Is it necessary to ensures that all processing has been completed?
p.WaitForExit();

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Diagnostics.ProcessquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions