Created
June 29, 2012 19:42
-
-
Save snluu/3020211 to your computer and use it in GitHub Desktop.
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
using System.Threading.Tasks; | |
static void SleepThenPrintSquare(int n) { | |
Thread.Sleep(2000); | |
Console.WriteLine("{0}", n * n); | |
} | |
static void Main() { | |
var tasks = new List<Task>(5); | |
for (int i = 1; i <= 5; i++) | |
tasks.Add(Task.Factory.StartNew(() => SleepThenPrintSquare(i))); | |
// Wait for all tasks to finish | |
foreach (var t in tasks) | |
t.Wait(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment