Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace MultithreadingTest
  10. {
  11. class PriorityTest
  12. {
  13. public static int CurrentThread = 1;
  14. public static List<DateTime> fDts1 = new List<DateTime>();
  15. public static List<DateTime> fDts2 = new List<DateTime>();
  16.  
  17. public static void Main()
  18. {
  19. Process.GetCurrentProcess().ProcessorAffinity = (IntPtr) (2);
  20.  
  21. var firstThread = new Thread(() => Do(1, fDts1));
  22. var secondThread = new Thread(() => Do(2, fDts2));
  23.  
  24. firstThread.Start();
  25. secondThread.Start();
  26.  
  27. Thread.Sleep(TimeSpan.FromSeconds(5));
  28. firstThread.Abort();
  29. secondThread.Abort();
  30.  
  31. var fDts = fDts1.Concat(fDts2).OrderBy(e => e).ToList();
  32. for (var i = 1; i < fDts.Count; i++)
  33. {
  34. Console.WriteLine(fDts[i].Subtract(fDts[i-1]).TotalMilliseconds);
  35. }
  36. }
  37.  
  38. public static void Do(int name, List<DateTime> fDts)
  39. {
  40. while (true)
  41. {
  42. if (CurrentThread != name)
  43. {
  44. fDts.Add(DateTime.Now);
  45. CurrentThread = name;
  46. }
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement