suggest change
var random = new Random();
IEnumerable<Task<int>> tasks = Enumerable.Range(1, 5).Select(n => Task.Run(async() =>
    Console.WriteLine("I'm task " + n);
    await Task.Delay(random.Next(10,1000));
    return n;

Task<Task<int>> whenAnyTask = Task.WhenAny(tasks);
Task<int> completedTask = await whenAnyTask;
Console.WriteLine("The winner is: task " + await completedTask);

await Task.WhenAll(tasks);
Console.WriteLine("All tasks finished!");

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents