© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
12 replies
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);
// 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");
    }
  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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Does it work like this?
C#CC# / help
7mo ago
✅ Does it work like this?
C#CC# / help
10mo ago
Why does this work the way it does
C#CC# / help
8mo ago
why does this Not work?
C#CC# / help
3y ago