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); } }
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(); }
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); } }