public void CheckIfNumbersArePrime() { while (true) { var numberToCheck = _numbersToCheck.Dequeue(); if (numberToCheck > -1) //If the queue was empty, just dont do anything. { if (IsNumberPrime(numberToCheck)) { _primeNumbers.Add(numberToCheck); } _numbersToCheck.Consumed(); } else { return; } //We are done. Stop hogging the cpu let other threads finish. very minor optimization. //But since we have 2 threads per core. It might matter. //Actually, you are running this on an i7 which has hyperthreading. So Im not sure. } }