private static void ProducerJob() { Random rng = new Random(0); ProducerConsumer producatorCons = new ProducerConsumer(); while (index.Index < 100) { int number = 0; lock (index) { number = index.Index; index.Index++; } if (number < 100) { Console.WriteLine("Producing {0}", number); producatorCons.Produce(number); Thread.Sleep(rng.Next(600)); } } }
static void ConsumerJob() { Random rng = new Random(1); ProducerConsumer producatorCons = new ProducerConsumer(); while (consumeIndex.Index < 100) { //lock (consumeIndex) //{ if (consumeIndex.Index < 100) { object o = producatorCons.Consume(); Console.WriteLine("\t\t\t\tConsuming {0}", o); Thread.Sleep(rng.Next(1000)); lock (consumeIndex) { consumeIndex.Index++; } } //} } }