Skip to content

await Task.WhenAny(new List<Task>()) should not Hang #55578

Closed
@TonyValenti

Description

@TonyValenti

Description

Run this code:

await Task.WhenAny(new List<Task>())

And it will hang your process.

This is a highly undesirable default behavior. It is not obvious this will hang and there is no easy way to detect that this was the cause.

Other information

I recommend one of the following adjustments:
If using Task.WhenAny() on an empty list/enumerable/array:
A) Throw a Sequence contains no elements exception.
OR
B) Immediately return Task.CompletedTask or Task.FromResult(default(T))

I am OK with either, but I think that A is the best option.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions