Created
May 30, 2012 19:30
-
-
Save AlphaGit/2838443 to your computer and use it in GitHub Desktop.
Async without async
This file contains 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) | |
{ | |
long number = 4278; | |
var t = new Thread(() => FactorNumber(number, FactorizationDone)); | |
t.Start(); | |
t.Join(); | |
Console.ReadKey(); | |
} | |
static void FactorizationDone(ISet<long> result) | |
{ | |
Console.WriteLine("The work is done, the results are: {0}", string.Join(", ", result)); | |
} | |
static void FactorNumber(long number, Action<ISet<long>> callback) | |
{ | |
var dividers = new SortedSet<long>(); | |
for (long i = 1; i < number; i++) | |
{ | |
if (number % i == 0) | |
dividers.Add(i); | |
} | |
callback(dividers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment