Last active
August 29, 2015 14:20
-
-
Save i3arnon/fe08aaff77a0ce29bb8f to your computer and use it in GitHub Desktop.
async for yarin
This file contains hidden or 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
rivate static void Main() | |
{ | |
CountToFiftyAsync().Wait(); | |
} | |
private static async Task CountToFiftyAsync() | |
{ | |
var taskA = CountToAsync("a", 10); | |
var taskB = CountToAsync("b", 10); | |
var taskC = CountToAsync("c", 10); | |
var taskD = CountToAsync("d", 10); | |
var taskE = CountToAsync("e", 10); | |
await Task.WhenAll(taskA, taskB, taskC, taskD, taskE); | |
} | |
private static async Task CountToAsync(string key, int countTo) | |
{ | |
for (int i = 0; i < countTo; i++) | |
{ | |
await Task.Delay(1000); | |
Console.WriteLine("{0}: {1}", key, i + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment