Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. //PRZYKLAD NA TASKACH
  10. class Program
  11. {
  12. private static int N = 0;
  13. private static void Inc()
  14. {
  15. int n;
  16. n = N;
  17. Console.WriteLine("task {0} take N={1}", Task.CurrentId, n);
  18. n = n + 1;
  19. N = n;
  20. Console.WriteLine("task {0} take N={1}", Task.CurrentId, n);
  21. }
  22. static void Main(string[] args)
  23. {
  24. Task[] task = new Task[5];
  25. for (int ID=0; ID<task.Length; ID++)
  26. {
  27. task[ID] = new Task(Inc);
  28. }
  29. foreach(Task t in task)
  30. {
  31. t.Start();
  32. }
  33. foreach(Task t in task)
  34. {
  35. t.Wait();
  36. }
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement