Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace MultithreadingTest
- {
- class PriorityTest
- {
- public static int CurrentThread = 1;
- public static List<DateTime> fDts1 = new List<DateTime>();
- public static List<DateTime> fDts2 = new List<DateTime>();
- public static void Main()
- {
- Process.GetCurrentProcess().ProcessorAffinity = (IntPtr) (2);
- var firstThread = new Thread(() => Do(1, fDts1));
- var secondThread = new Thread(() => Do(2, fDts2));
- firstThread.Start();
- secondThread.Start();
- Thread.Sleep(TimeSpan.FromSeconds(5));
- firstThread.Abort();
- secondThread.Abort();
- var fDts = fDts1.Concat(fDts2).OrderBy(e => e).ToList();
- for (var i = 1; i < fDts.Count; i++)
- {
- Console.WriteLine(fDts[i].Subtract(fDts[i-1]).TotalMilliseconds);
- }
- }
- public static void Do(int name, List<DateTime> fDts)
- {
- while (true)
- {
- if (CurrentThread != name)
- {
- fDts.Add(DateTime.Now);
- CurrentThread = name;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement