Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Task.WhenAny prioritize some tasks over others?

When passing multiple completed tasks to Task.WhenAny does Task.WhenAny give a preference to which task completed Task will be returned?

like image 305
Zachary Burns Avatar asked Sep 07 '25 08:09

Zachary Burns


1 Answers

When you want to know the exact behavior, you can often check the reference source. For instance, WhenAny can be found here.

When looking through the source, note that the returned task is not one of your tasks, but an internally-created task (either a CompleteOnInvokePromise instance or continuation of it), whose Result will be one of your tasks. In the case where you are passing completed tasks into WhenAny, the Result is immediately set to the first completed task it encounters.

like image 56
seairth Avatar answered Sep 09 '25 23:09

seairth