Created
May 30, 2012 21:28
-
-
Save AlphaGit/2839080 to your computer and use it in GitHub Desktop.
Async with async, CPU bound
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
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