Esempio n. 1
0
 public void run()
 {
     // infinitely add stuff
     while (true)
     {
         // lock the queue
         lock (Question1.queue)
         {
             // dequeue if queue is not empty
             if (Question1.queue.q.Count > 0)
             {
                 Question1.queue.Dequeue();
             }
         }
         // print out the queue after adding
         Question1.printQueue();
         Thread.Sleep(10);
     }
 }
Esempio n. 2
0
        public void run()
        {
            // random number generator to insert rand values
            Random rand = new Random();

            while (true)
            {
                // lock the queue
                lock (Question1.queue)
                {
                    // check if it has reached capacity before inserting
                    if (Question1.queue.q.Count < Question1.queue.Limit)
                    {
                        Question1.queue.Enqueue(rand.Next());
                    }
                }

                // print queue and sleep
                Question1.printQueue();
                Thread.Sleep(10);
            }
        }