Skip to content

Instantly share code, notes, and snippets.

@cbrevik
Created October 24, 2023 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbrevik/b8cabc0ad64a200eb22b30550111bf88 to your computer and use it in GitHub Desktop.
Save cbrevik/b8cabc0ad64a200eb22b30550111bf88 to your computer and use it in GitHub Desktop.
Parallell or not
async Task Hey(long timestamp)
{
await Task.Delay(1000);
Console.WriteLine($"Hey! Time elapsed: {(DateTime.UtcNow.Ticks - timestamp) / 10000}ms");
}
async Task Yo(long timestamp)
{
await Task.Delay(1000);
Console.WriteLine($"Yo! Time elapsed: {(DateTime.UtcNow.Ticks - timestamp) / 10000}ms");
}
async Task Main()
{
Console.WriteLine("Without awaiting:");
var now = DateTime.UtcNow.Ticks;
var heyTask = Hey(now);
var yoTask = Yo(now);
await heyTask;
await yoTask;
Console.WriteLine("With awaiting:");
var now2 = DateTime.UtcNow.Ticks;
await Hey(now2);
await Yo(now2);
}
Main();
Console.ReadKey(true);
@cbrevik
Copy link
Author

cbrevik commented Oct 24, 2023

Without awaiting:
Hey! Time elapsed: 1006ms
Yo! Time elapsed: 1006ms
With awaiting:
Hey! Time elapsed: 1001ms
Yo! Time elapsed: 2004ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment