C#C
C#3y ago
konakona

❔ ✅ Why does it work like that

I'm learning async, came up with this code. Found some info but my dumb ass didn't understand it.
// 1
var first = AsyncPrint(1);
var second = AsyncPrint(2);
var third = AsyncPrint(3);

await first;
await second;
await third;

// 2
await AsyncPrint(1);
await AsyncPrint(2);
await AsyncPrint(3);


  public static async Task AsyncPrint(int index)
    {
        Console.WriteLine($"print {index} started");
        await Task.Delay(5000);
        Console.WriteLine($"print {index} stopped");
    }


why does 1 work as async threads (~5 seconds) and 2 works like regular ones (~15 seconds)? Either way I use a Task with await
Was this page helpful?