static void Main(string[] args) { Queue <int> queue = new Queue <int>(); SyncEvents syncevents = new SyncEvents(); Console.WriteLine("Configuring worker threads..."); Producer producer = new Producer(queue, syncevents); Consumer consumer = new Consumer(queue, syncevents); Thread producerThread = new Thread(producer.ThreadRun); Thread consumerThread = new Thread(consumer.ThreadRun); Console.WriteLine("Launching producer and consumer threads..."); producerThread.Start(); consumerThread.Start(); for (int i = 0; i < 4; i++) { Thread.Sleep(2500); ShowQueueContents(queue); } Console.WriteLine("Signaling threads to terminate..."); syncevents.ExitThreadEvent.Set(); producerThread.Join(); consumerThread.Join(); Console.Read(); }
public Consumer(Queue <int> q, SyncEvents e) { _queue = q; _syncEvents = e; }
public Producer(Queue <int> q, SyncEvents e) { _queue = q; _syncEvents = e; }