Add analyzer for async delegates with LongRunning tasks#311
Merged
SergeyTeplyakov merged 2 commits intomasterfrom Jul 1, 2025
Merged
Add analyzer for async delegates with LongRunning tasks#311SergeyTeplyakov merged 2 commits intomasterfrom
SergeyTeplyakov merged 2 commits intomasterfrom
Conversation
Introduces EPC36, which warns when async delegates are used with Task.Factory.StartNew and TaskCreationOptions.LongRunning. Adds analyzer implementation, tests, documentation, and diagnostic descriptor. This helps prevent inefficient use of threads and clarifies intent when working with async code.
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds a new analyzer (EPC36) that warns when async delegates are used with Task.Factory.StartNew combined with TaskCreationOptions.LongRunning, to prevent inefficient thread usage and clarify intent in async code.
- Introduces
DiagnosticDescriptorEPC36 inDiagnosticDescriptors.cs. - Implements analyzer logic in
DoNotUseAsyncDelegatesForLongRunningTasksAnalyzer.cs, along with unit tests. - Updates release notes and adds documentation for the new rule.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ErrorProne.NET.CoreAnalyzers/DiagnosticDescriptors.cs | Added EPC36 diagnostic descriptor for async delegates with LongRunning |
| src/ErrorProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotUseAsyncDelegatesForLongRunningTasksAnalyzer.cs | Implemented analyzer logic to detect async delegates in StartNew calls with LongRunning |
| src/ErrorProne.NET.CoreAnalyzers/AnalyzerReleases.Unshipped.md | Included EPC36 in the list of pending analyzer releases |
| src/ErrorProne.NET.CoreAnalyzers.Tests/AsyncAnalyzers/DoNotUseAsyncDelegatesForLongRunningTasksAnalyzerTests.cs | Added comprehensive tests covering correct and incorrect scenarios |
| docs/Rules/EPC36.md | Created documentation with examples and guidance for EPC36 |
Comments suppressed due to low confidence (1)
docs/Rules/EPC36.md:10
- The ordered list numbering jumps from 1 to 3. Renumber this item as '2.' to maintain correct sequence.
3. **Creating confusion**: The intent of the code becomes unclear - is it meant to be long-running synchronous work or efficient async work? Is it really the case that the synchronous block of the async method is taking a long time, or it's just a mistake?
...rProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotUseAsyncDelegatesForLongRunningTasksAnalyzer.cs
Show resolved
Hide resolved
...rProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotUseAsyncDelegatesForLongRunningTasksAnalyzer.cs
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces EPC36, which warns when async delegates are used with Task.Factory.StartNew and TaskCreationOptions.LongRunning. Adds analyzer implementation, tests, documentation, and diagnostic descriptor. This helps prevent inefficient use of threads and clarifies intent when working with async code.