Skip to content

Instantly share code, notes, and snippets.

@snluu
Created June 29, 2012 19:42
Show Gist options
  • Save snluu/3020211 to your computer and use it in GitHub Desktop.
Save snluu/3020211 to your computer and use it in GitHub Desktop.
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