public void Work() { while (true) { if (Monitor.TryEnter(Tray)) { int amount = rng.Next(1, 4); for (int i = 0; i < amount; i++) { if (Tray.Position == 0) { break; } Drink drink = Tray.Pull(); Thread.Sleep(rng.Next(100, 250)); PulledDrink?.Invoke(drink); } Monitor.Pulse(Tray); Monitor.Exit(Tray); } Thread.Sleep(3000); } }