Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- //PRZYKLAD NA TASKACH
- class Program
- {
- private static int N = 0;
- private static void Inc()
- {
- int n;
- n = N;
- Console.WriteLine("task {0} take N={1}", Task.CurrentId, n);
- n = n + 1;
- N = n;
- Console.WriteLine("task {0} take N={1}", Task.CurrentId, n);
- }
- static void Main(string[] args)
- {
- Task[] task = new Task[5];
- for (int ID=0; ID<task.Length; ID++)
- {
- task[ID] = new Task(Inc);
- }
- foreach(Task t in task)
- {
- t.Start();
- }
- foreach(Task t in task)
- {
- t.Wait();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement