void ProduceLuggage() { while (true) { //lock the splitters incoming luggage Monitor.Enter(splitter); Luggage newLuggage = GenerateLuggage(); splitter.Enqueue(newLuggage); //Add luggage to the counter of lifetime made. LuggageMade++; Debug.WriteLine($"[{Thread.CurrentThread.Name}] [{newLuggage.flightplan.Departure}] [{LuggageMade}] Har sendt baggage til splitter"); //Tell that luggage were made LuggageCreated?.Invoke(this, EventArgs.Empty); //Tell all waiting threads its available and exit thread Monitor.PulseAll(splitter); Monitor.Exit(splitter); //Make some more randomness to make the timing of all counters random int b = 4500; byte roll = RollDice((byte)b); Thread.Sleep(roll); Thread.Sleep(rnd.Next(600, 1200)); } }
private void Counter_LuggageCreated(object sender, EventArgs e) { LuggageCreated?.Invoke(sender, e); }