Reputation: 473
When passing multiple completed tasks to Task.WhenAny does Task.WhenAny give a preference to which task completed Task will be returned?
Upvotes: 4
Views: 271
Reputation: 2062
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.
Upvotes: 2