コード例 #1
0
        private void Consumer()
        {
            int Value;

            while (true)
            {
                semFull.WaitOne();
                semMutex.WaitOne();
                Value = buffer.Dequeue();
                ConsumerListView.BeginInvoke(new ShowConsumerActionDelegate(ShowConsumerAction), Value);
                BufferLabel.BeginInvoke(new ShowBufferDelegate(ShowBuffer));
                semMutex.Release();
                semEmpty.Release();
                Thread.Sleep(random.Next(500, 2000));
            }
        }
コード例 #2
0
        private void Producer()
        {
            int Value;

            while (true)
            {
                Value = random.Next(1, 100);
                semEmpty.WaitOne();
                semMutex.WaitOne();
                buffer.Enqueue(Value);
                ProducerListView.BeginInvoke(new ShowProducerActionDelegate(ShowProducerAction), Value);
                BufferLabel.BeginInvoke(new ShowBufferDelegate(ShowBuffer));
                semMutex.Release();
                semFull.Release();
                Thread.Sleep(random.Next(500, 2000));
            }
        }