static void Main(string[] args) { int numTasks = 20; var state = new SharedState(); var tasks = new Thread[numTasks]; for (int i = 0; i < numTasks; i ++ ) { tasks[i] = new Thread(new Job(state).DoTheJob); tasks[i].Start(); } for (int i = 0; i < numTasks; i++) { tasks[i].Join(); } Console.WriteLine("summarized {0}", state.State); }
public Job(SharedState sharedState) { this.sharedState = sharedState; }