Пример #1
0
        public static void Start()
        {
            int numTasks = 5;
            var state    = new SharedState();
            var tasks    = new Task[numTasks];

            //start 20 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);
        }
Пример #2
0
 public Job(SharedState sharedState)
 {
     this.sharedState = sharedState;
 }