-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Use CancellationToken.ThrowIfCancellationRequested #33809
Closed
Labels
api-approved
API was approved in API review, it can be implemented
area-System.Threading
code-analyzer
Marks an issue that suggests a Roslyn analyzer
code-fixer
Marks an issue that suggests a Roslyn code fixer
help wanted
[up-for-grabs] Good issue for external contributors
Milestone
Comments
terrajobst
added
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Threading
code-analyzer
Marks an issue that suggests a Roslyn analyzer
labels
Mar 19, 2020
Dotnet-GitSync-Bot
added
the
untriaged
New issue has not been triaged by the area owner
label
Mar 19, 2020
jeffhandley
added
the
code-fixer
Marks an issue that suggests a Roslyn code fixer
label
Mar 21, 2020
Estimates:
|
terrajobst
removed
the
untriaged
New issue has not been triaged by the area owner
label
Mar 21, 2020
jeffschwMSFT
added
untriaged
New issue has not been triaged by the area owner
and removed
untriaged
New issue has not been triaged by the area owner
labels
Apr 9, 2020
Suggested severity: Info void MyMethod(CancellationToken c)
{
// A) Simple check
// Before
if (c.IsCancellationRequested)
{
// Not sure if we want to cover other overloads as we cannot pass the parameters
throw new OperationCanceledException();
}
// After
c.ThrowIfCancellationRequested();
// A) Negated check
// Before
if (!c.IsCancellationRequested)
{
DoSomething();
}
else
{
throw new OperationCanceledException();
}
// After
c.ThrowIfCancellationRequested();
DoSomething();
// Excluded cases:
// B) Multiple conditions in the if statement
if (c.IsCancellationRequested && otherCondition)
{
throw new OperationCanceledException();
}
// C) There is extra logic in the if body
if (c.IsCancellationRequested)
{
SomeOtherCode();
throw new OperationCanceledException();
}
} |
carlossanlop
added
api-ready-for-review
API is ready for review, it is NOT ready for implementation
and removed
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
labels
Jan 15, 2021
terrajobst
added
api-approved
API was approved in API review, it can be implemented
and removed
api-ready-for-review
API is ready for review, it is NOT ready for implementation
labels
Feb 4, 2021
|
I would like to be assigned to this. |
This was implemented as CA2250. Thanks! |
ghost
locked as resolved and limited conversation to collaborators
Aug 12, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
api-approved
API was approved in API review, it can be implemented
area-System.Threading
code-analyzer
Marks an issue that suggests a Roslyn analyzer
code-fixer
Marks an issue that suggests a Roslyn code fixer
help wanted
[up-for-grabs] Good issue for external contributors
Flag code that does
if (token.IsCancellationRequested) throw new OperationCanceledException();
orif (token.IsCancellationRequested) throw new OperationCanceledException(token);
and replace withtoken.ThrowIfCancellationRequested();
.Category: Style
The text was updated successfully, but these errors were encountered: