//Removes a drink object from conveyor in parameter if there are any public void Consume(object conveyor) { Drink drink; Conveyor tempCon = (Conveyor)conveyor; while (true) { lock (Automat._lock) { while (tempCon.load.Count > 0) { drink = tempCon.load.Peek(); Console.WriteLine("I drink " + drink.brand); tempCon.load.Dequeue(); consumeCount++; Console.WriteLine("I have drank a total of " + consumeCount + " " + drink.brand); Monitor.PulseAll(Automat._lock); Thread.Sleep(500); } Monitor.Wait(Automat._lock); } } }
void PutOnConveyor(Conveyor conveyor, Drink drink) { conveyor.load.Enqueue(drink); }