You can make Main()
method async
as well and use WhenAll
instead of WaitAll
. And use just T()
when assign Task
to array item, there is no need to do it like that new Task(async () => await T());
static async Task Main()
{
var tasks = new Task<bool>[10];
for (int i = 0; i < 10; i++)
{
tasks[i] = T();
}
await Task.WhenAll(tasks);
for (int i = 0; i < tasks.Length; i++)
{
Console.WriteLine($"Task {i} result = {tasks[i].Result}");
}
Console.ReadKey();
}
solved How to run many tasks and get their result after all of them ended?