Skip to content

Instantly share code, notes, and snippets.

@i3arnon
Last active August 29, 2015 14:20
Show Gist options
  • Save i3arnon/fe08aaff77a0ce29bb8f to your computer and use it in GitHub Desktop.
Save i3arnon/fe08aaff77a0ce29bb8f to your computer and use it in GitHub Desktop.
async for yarin
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