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
public async Task InitiateWaitTask() | |
{ | |
var delayTask = WaitAsync(); | |
delayTask.Wait(); | |
} | |
private static async Task WaitAsync() | |
{ | |
await Task.Delay(1000); | |
} |
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
var tasks = new List<int>() { 1, 2, 3 }.Select(WaitThreeSeconds); | |
await Task.WhenAll(tasks); |
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
var listOfInts = new List<int>() { 1, 2, 3 }; | |
var tasks = new List<Task>(); | |
foreach (var integer in listOfInts) | |
{ | |
var task = WaitThreeSeconds(integer); | |
tasks.Add(task); | |
} | |
await Task.WhenAll(tasks); |
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
private async Task WaitThreeSeconds(int param) | |
{ | |
Console.WriteLine($"{param} started ------ ({DateTime.Now:hh:mm:ss}) ---"); | |
await Task.Delay(3000); | |
Console.WriteLine($"{ param} finished ------({ DateTime.Now:hh: mm: ss}) ---"); | |
} |
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
var listOfInts = new List<int>() { 1, 2, 3 }; | |
foreach (var integer in listOfInts) | |
{ | |
await WaitThreeSeconds(integer); | |
} |