public static void DemoWithTasks() { var cooksAsTasks = Cooking.TheCooks .Select(name => Task.Factory.StartNew(Cooking.GoCook)) .ToArray(); Cooking.GoCook(); Task.WaitAll(cooksAsTasks); }
public static void DemoWithThreads() { var cooksAsThreads = Cooking.TheCooks .Select(name => new Thread(Cooking.GoCook) { Name = name }) .ToList(); foreach (var cookAsThread in cooksAsThreads) { cookAsThread.Start(); } Cooking.GoCook(); foreach (var childThread in cooksAsThreads) { childThread.Join(500); } }