Answer the question
In order to leave comments, you need to log in
Why does Task.WhenAll() hang when doing multiple tasks?
I want to run multiple tasks at the same time
static async void TestMethod()
{
Task<string>[] allTasks = new Task<string>[5];
for(int i = 0; i < 5; i++)
{
int j = i;
allTasks[i] = new Task<string>(() => { return "#" + j; });
}
var resultTask = Task.WhenAll(allTasks);
Console.WriteLine(resultTask.Status);
var result = resultTask.Result;
foreach (var res in result)
{
Console.WriteLine("1");
Console.WriteLine(res);
}
Console.WriteLine("END");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question