Created
October 24, 2023 09:44
-
-
Save cbrevik/b8cabc0ad64a200eb22b30550111bf88 to your computer and use it in GitHub Desktop.
Parallell or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Author
cbrevik
commented
Oct 24, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment