void GetLuggage() { while (true) { Monitor.Enter(IncomingLuggage); while (IncomingLuggage.Count == 0) { //Wait for luggage to come in, and immediately send it out Monitor.Wait(IncomingLuggage); } LuggageSent?.Invoke(this, EventArgs.Empty); for (int i = 0; i < rnd.Next(0, IncomingLuggage.Count); i++) { SplitLuggage(IncomingLuggage.Dequeue()); } Monitor.Exit(IncomingLuggage); Thread.Sleep(rnd.Next(100, 300)); } }
private void Splitter_LuggageSent(object sender, EventArgs e) { LuggageSent?.Invoke(this, e); }