public static void Start() { int numTasks = 5; var state = new SharedState(); var tasks = new Task[numTasks]; //start 5 tasks with shared state for (int i = 0; i < numTasks; i++) { tasks[i] = Task.Run(() => new Job(state).DoTheJob()); } Task.WaitAll(tasks); Console.WriteLine("summarized {0}", state.State); }
public Job(SharedState sharedState) { this.sharedState = sharedState; }