Skip to content

Conversation

breyed
Copy link
Contributor

@breyed breyed commented May 17, 2020

Task.Run accepts a cancellation token, but doesn't provide it to the invoked method. The cancellation token is only used to cancel the action if it has not started running.
This edit corrects the following problems:

  • Summary sentence about cancelation didn't indicate that it only applies before the action starts running.
  • Summary sentence was inconsistently present across the various Run overloads.
  • The cancelationToken parameter offered inconsistent guidance.
  • The cancelationToken parameter for one overload said it "should" be provided. This is often poor guidance. In systems were the thread utilization is low, the action will start immediately, and there is no point in providing a cancellation token. It is often useful to provide a cancellation token to the action, but that's not what the cancelationToken parameter in Run does. Further updates to the docs to clarify this may be helpful.

Task.Run accepts a cancellation token, but doesn't provide it to the invoked method. The cancellation token is only used to cancel the action if it has not started running.
This edit corrects the following problems:
* Summary sentence about cancelation didn't indicate that it only applies before the action starts running.
* Summary sentence was inconsistently present across the various Run overloads.
* The `cancelationToken` parameter offered inconsistent guidance.
* The `cancelationToken` parameter for one overload said it "should" be provided. This is often poor guidance. In systems were the thread utilization is low, the action will start immediately, and there is no point in providing a cancellation token. It is often useful to provide a cancellation token to the action, but that's not what the `cancelationToken` parameter in `Run` does. Further updates to the docs to clarify this may be helpful.
@dotnet-bot dotnet-bot added this to the May 2020 milestone May 17, 2020
@breyed breyed changed the title Clarify scope of cancelation in Task.Run Clarify scope of cancellation in Task.Run May 17, 2020
Copy link
Contributor

@mairaw mairaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions to fix the build errors

@mairaw
Copy link
Contributor

mairaw commented Jun 10, 2020

@breyed I've unresolved my comments since my suggestions weren't applied. Can you make sure that you click the commit suggestion button?

Copy link
Contributor

@gewarren gewarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some build warnings.

Copy link
Contributor

@gewarren gewarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still build warnings.

@gewarren gewarren requested review from tarekgh and stephentoub August 3, 2020 21:54
@gewarren gewarren merged commit 3369f85 into dotnet:master Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants