private void Consumption(SmartWarehouse<FormattedText> warehouse) { cancelationFlag = false; bool passwordFound = false; while (!cancelationFlag && !passwordFound) { Console.WriteLine("Consumer is trying to take the Password."); FormattedText temporaryPassword; bool passwordWasTaken = warehouse.TryTake(out temporaryPassword, PasswordTakingMaximumTime); if (passwordWasTaken) { Console.WriteLine("Consumer took the Password."); if (temporaryPassword.CompareTo(desiredPassword) == 0) { Console.WriteLine("Consumer found the Password."); passwordFound = true; if (OnDesiredPasswordFound != null) OnDesiredPasswordFound(); } } else Console.WriteLine("Consumer was not able to take the Password due to maximum waiting time."); } IsConsumtionInProgress = false; }