Created
October 6, 2015 01:45
-
-
Save alexyakunin/c5d4e3ac93bc4162637f to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace CSharpAsyncRecursion | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Counted to {0}.", CountRecursivelyAsync(10000).Result); | |
} | |
static async Task<int> CountRecursivelyAsync(int count) | |
{ | |
await Task.Yield(); | |
if (count <= 0) | |
return count; | |
var result = 1 + await CountRecursivelyAsync(count - 1); | |
await Task.Yield(); | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment