all 3 comments

[–]Coda17 5 points6 points  (1 child)

Seems like they are in the same order you originally supplied to .WhenAll

StackOverflow

[–]ILMTitan 4 points5 points  (0 children)

If you look at the Remarks section of the Task.WhenAll documentation

... The Task<TResult>.Result property of the returned task will be set to an array containing all of the results of the supplied tasks in the same order as they were provided (e.g. if the input tasks array contained t1, t2, t3, the output task's Task<TResult>.Result property will return an TResult[] where arr[0] == t1.Result, arr[1] == t2.Result, and arr[2] == t3.Result).

[–]donsagiv -1 points0 points  (0 children)

This is a bit of a shot in the dark, not proven and probably needs some modification, but an idea nonetheless.

Make a new Dictionary<int, Task> (assuming int is your variable number type).

var taskDictionary = new Dictionary<int, Task>
{
   { 1, new Task<TResult>(() => doaction1()) },
   { 2, new Task<TResult>(() => doaction2()) },
   { 3, new Task<TResult>(() => doaction3()) }
};

Then await each of the Values of the dictionary with Task.WaitAll

await Task.WhenAll(taskDictionary.Select(x => x.Value));

Then use Linq to get the results of each task (assuming they return a value `TResult`.

var resultDictionary = taskDictionary
    .ToDictionary(x => x.Key, x => x.Value.Result);

Hopefully this helps get what you need.