Skip to content

Instantly share code, notes, and snippets.

@AlphaGit
Created May 30, 2012 21:28
Show Gist options
  • Save AlphaGit/2839080 to your computer and use it in GitHub Desktop.
Save AlphaGit/2839080 to your computer and use it in GitHub Desktop.
Async with async, CPU bound
class Program
{
static void Main(string[] args)
{
StartWork();
Console.WriteLine("Processing is happening right now..");
Console.ReadKey();
}
static async Task StartWork()
{
long number = 4278;
var result = await Task.Run(() => FactorNumber(number));
Console.WriteLine("The work is done, the results are: {0}", string.Join(", ", result));
}
static ISet<long> FactorNumber(long number)
{
var dividers = new SortedSet<long>();
for (long i = 1; i < number; i++)
{
if (number % i == 0)
dividers.Add(i);
}
return dividers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment