Skip to content

Add Task.WithCancellation(CancellationToken) method #27722

@AArnott

Description

@AArnott

The WithCancellation extension method is super-useful. Should we add it to the .NET Framework / .NET Standard itself?

The risk is that folks will misunderstand the subtle yet important difference between using this method and passing the CancellationToken into the original async method properly.

Preferably this is not an extension method so it doesn't conflict with extension methods that folks have already defined. It should just override them, assuming the semantics are equivalent (the type of exception thrown, etc.)

See also the source code for its definition in the vs-threading library.

As discussed in davidfowl/AspNetCoreDiagnosticScenarios#8 with @davidfowl.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions