コード例 #1
0
        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();
        }
コード例 #2
0
 public Consumer(Queue <int> q, SyncEvents e)
 {
     _queue      = q;
     _syncEvents = e;
 }
コード例 #3
0
 public Producer(Queue <int> q, SyncEvents e)
 {
     _queue      = q;
     _syncEvents = e;
 }