Ejemplo 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);
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Question1 q1 = new Question1();

            q1.Answer();
            Question2 q2 = new Question2();

            q2.Answer();
            Question3 q3 = new Question3();

            q3.Answer();
            Question4 q4 = new Question4();

            q4.Answer();
            Question5 q5 = new Question5();

            q5.Answer();
            Question6 q6 = new Question6();

            q6.Answer();
        }
Ejemplo n.º 3
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);
            }
        }