Skip to content

Confusion with Task.WhenAny #44497

Open
Open
@Ginomed

Description

@Ginomed

Type of issue

Missing information

Description

Thank you for the great article.
I have a problem to understand the following passage:

Near the end, you see the line await finishedTask;. The line await Task.WhenAny doesn't await the finished task. It awaits the Task returned by Task.WhenAny. The result of Task.WhenAny is the task that has completed (or faulted).

Could you explain the difference between the two tasks? They have the same Id.
I understand what you say in the next sentence though.

You should await that task again, even though you know it's finished running. That's how you retrieve its result, or ensure that the exception causing it to fault gets thrown.

Page URL

https://learn.microsoft.com/de-de/dotnet/csharp/asynchronous-programming/

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/asynchronous-programming/index.md

Document Version Independent Id

3001f6f2-b04b-5513-54a6-fedfccc94e51

Article author

@BillWagner

Metadata

  • ID: 79c2a674-a335-4802-5c52-4a2af998cc7f
  • Service: dotnet-csharp
  • Sub-service: async-task-programming

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions