public CustomThread GenerateThread() { Random rnd = new Random(); int priority = rnd.Next(1, 10); int time = rnd.Next(1, 30); CustomThread thread = new CustomThread(time, priority); return(thread); }
int maxSum = 100; //максимальна кылькысть заявок public void Execute(int a) { checkQueue.Enqueue(start); while (checkQueue.Count > 0) { checkQueue = new Queue <CustomThread>(checkQueue.OrderBy(c => c.Priority)); CustomThread current = checkQueue.Dequeue().DeepClone(); if (allThreads.Count <= maxSum) { int time = a;//GenerateTime(); CustomThread pretendent = GenerateThread().DeepClone(); if (pretendent.Priority < current.Priority) { globalTime += time; checkQueue.Enqueue(current); checkQueue.Enqueue(pretendent); } else { globalTime += current.Time; checkQueue.Enqueue(pretendent); allThreads.Enqueue(current); } } else { globalTime += current.Time; } } Console.WriteLine(globalTime / allThreads.Count); // Console.WriteLine(counter); ; //foreach (var item in allThreads) //{ // Console.Write(item.Priority ); // Console.WriteLine(); //} }