I have a bunch of async web queries that I need to run at application startup. Why in this example both tasks execute even if I comment out this line?
//await Task.WhenAll(tasks);
It seems that there is no difference whether I use Task.WhenAll() or not. How come?
static void Main(string[] args)
{
Execute();
Console.ReadKey();
}
private static async void Execute()
{
Func<Task> Task1 = (async () =>
{
await Task.Delay(1000);
Console.WriteLine("Task 1 completed.");
});
var tasks = new List<Task> { Task1(), Task2() };
await Task.WhenAll(tasks);
}
private static async Task Task2()
{
await Task.Delay(1000);
Console.WriteLine("Task 2 completed.");
}