Skip to content

Use AsParallel() correctly #33769

Open
dotnet/roslyn-analyzers
#4126
@terrajobst

Description

@terrajobst

Using .AsParallel() at the end of a LINQ query, e.g. foreach (var item in src.Select(...).Where(...).AsParallel(...)), is a nop and should either be removed or the AsParallel() moved earlier in the query. I've even seen developers write foreach (var item in src.AsParallel()) thinking it parallelizes the foreach loop, which it doesn't... it'd be good to warn about such misuse.

Category: Performance

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Linq.Parallelcode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions