Skip to content

Instantly share code, notes, and snippets.

@alexyakunin
Created October 6, 2015 01:45
Show Gist options
  • Save alexyakunin/c5d4e3ac93bc4162637f to your computer and use it in GitHub Desktop.
Save alexyakunin/c5d4e3ac93bc4162637f to your computer and use it in GitHub Desktop.
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