-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Clarify scope of cancellation in Task.Run #4253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
There was a problem hiding this 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
@breyed I've unresolved my comments since my suggestions weren't applied. Can you make sure that you click the commit suggestion button? |
Co-authored-by: Maira Wenzel <[email protected]>
Co-authored-by: Maira Wenzel <[email protected]>
Co-authored-by: Maira Wenzel <[email protected]>
Co-authored-by: Maira Wenzel <[email protected]>
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still build warnings.
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:
cancelationToken
parameter offered inconsistent guidance.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 thecancelationToken
parameter inRun
does. Further updates to the docs to clarify this may be helpful.