Skip to content

VSTHRD103 false positive for Task.WhenAll with Select #1662

Closed

Description

With Microsoft.VisualStudio.Threading.Analyzers 18.7.115, VSTHRD103 reports the Enumerable.Select call in this parallel asynchronous fan-out pattern:

private async Task ProcessAllAsync(IEnumerable<Item> items)
{
    await Task.WhenAll(items.Select(ProcessAsync));
}

private Task ProcessAsync(Item item) => /* ... */;

Select is intentionally synchronous here. It projects each item to a Task, and Task.WhenAll then asynchronously waits for every operation while preserving concurrent execution. Replacing this with an asynchronous LINQ operator is not equivalent and may serialize the operations.

Expected: VSTHRD103 should recognize Task.WhenAll(source.Select(SomeAsync)) as a legitimate asynchronous pattern and not report the Select invocation.

The diagnostic also occurs if the selected tasks are first assigned to an IEnumerable<Task<T>> and then passed to Task.WhenAll.

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions