public void Judge(List <int> winners, List <TeamResult> teamResults) { //Queue a command to judge the outcome lock (mWorkerThreads) { //Hand the jobs out to the workers circularly ConcurrentQueue <DivisionWinnerCalculatorCommand> queue = mWorkerQueues[mWorkerIndex]; mWorkerIndex = (mWorkerIndex + 1) % NumWorkerThreads; queue.Enqueue(DivisionWinnerCalculatorCommand.CreateJudgeCommand(winners, teamResults)); } }
public void FinishSession(Action <int, List <int> > finishedCallback) { lock (mWorkerThreads) { //Tell all the workers to finish foreach (ConcurrentQueue <DivisionWinnerCalculatorCommand> queue in mWorkerQueues) { queue.Enqueue(DivisionWinnerCalculatorCommand.CreateFinishSessionCommand()); } //Wait for the worker threads to join foreach (Thread thread in mWorkerThreads) { thread.Join(); } mWorkerQueues.Clear(); mWorkerThreads.Clear(); } EndTime = DateTime.Now; finishedCallback?.Invoke(-1, null); }