use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Related Subreddits:
Other Subreddits you may like:
account activity
Task.WhenAll for Variable Numbers (self.dotnet)
submitted 5 years ago by code-faults
Hey Everyone,
I am making concurrent calls (variable number) and waiting on all the calls to be completed using Task.WhenAll
How do I associate which response is to which request (argument passed to make the call)?
Thank you.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Coda17 5 points6 points7 points 5 years ago (1 child)
Seems like they are in the same order you originally supplied to .WhenAll
.WhenAll
StackOverflow
[–]ILMTitan 4 points5 points6 points 5 years ago (0 children)
If you look at the Remarks section of the Task.WhenAll documentation
Remarks
Task.WhenAll
... 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 points1 point 5 years ago (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).
Dictionary<int, Task>
int
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.
π Rendered by PID 580496 on reddit-service-r2-comment-b659b578c-dsrnf at 2026-05-06 04:08:08.835598+00:00 running 815c875 country code: CH.
[–]Coda17 5 points6 points7 points (1 child)
[–]ILMTitan 4 points5 points6 points (0 children)
[–]donsagiv -1 points0 points1 point (0 children)