public void AssignTopPriorityPlayers() { // Search through queues for players with top priority var queues = PlayerQueue.GetQueues(); var prioritizedPlayers = new Queue <Player>(); Parallel.ForEach(queues, queue => { if (queue.Count > 0) { lock (queue) { long waitingTimeInMs = (DateTime.Now.Ticks - queue.Peek().QueueIngressTime) / 10_000; if (waitingTimeInMs > PlayerQueue.PlayerMaxWaitingTimeMs) { // Assign player as top priority, since it's been waiting for too long PlayerQueue.AssignTopPriorityToPlayer(queue.Dequeue()); } } } }); PlayerQueue.TryCreateMatchWithPriorityPlayers(_hostingEnvironment); }