// Sorting Method static void Sorting() { while (true) { if (counterConveyor.Count != 0) { // Dequeues the conveyor and Begin Sorting Bagage bagage = counterConveyor.Dequeue(); Console.WriteLine("----Sorting Machine Got Bagage ID:[{0}]", bagage.BagageId); SortingMachine.Instance.SortBagage(bagage); } } }
// Counter Method static void Counting() { Counter counter = new Counter(); while (true) { lock (bagageToCheckIn) { if (bagageToCheckIn.Count != 0) { // Dequeues from BagageToCheckIn and Enqueues The Conveyor to the sorting machine Bagage bagage = bagageToCheckIn.Dequeue(); counterConveyor.Enqueue(bagage); Console.WriteLine("--Counter[{0}] Checked Bagage [{1}] in", counter.CounterId, bagage.BagageId); Thread.Sleep(1000); } } } }
static void Main(string[] args) { BagageFactory bagageFactory = new BagageFactory(); Thread sortingThread = new Thread(Sorting); Thread reader = new Thread(Reader); // Starts as many counter Treads as the central server has been configed to for (int i = 0; i < CentralServer.Instance.Counters; i++) { Thread _counter = new Thread(Counting); _counter.Start(); } // Starts as many Terminal Treads as the central server has been configed to for (int i = 0; i < CentralServer.Instance.Terminals; i++) { Thread _terminal = new Thread(Terminaling); _terminal.Start(); } sortingThread.Start(); reader.Start(); // Keeps Creating new Bagage! while (true) { for (int i = 0; i < 10; i++) { Bagage bagage = bagageFactory.CreateBagage(); if (bagage != null) { bagageToCheckIn.Enqueue(bagage); Console.WriteLine("Bagage incomming! ID:[{0}]", bagage.BagageId); } Thread.Sleep(1000); } Thread.Sleep(1000); } }