title: Set maximum value for the progress bar to match length of queue.
body: <p>I would like to visualize how a queue when accessed by two reader threads and a writer thread grows and shrinks, with help of a progressbar in mainform. I will use a delegate to invoke the progress bar in main form and set its value to Queue.Value ( Toys.lenght). The progressbar does not behave as stated, it does not grow all the way and the lenght variables does not either. </p>
  
  <pre><code>     public class Buffer
       {
          private delegate void Display(int v, ProgressBar f );
          private Queue&lt;Toy&gt; Toys = new Queue&lt;Toy&gt;(); 
          private object MyLock = new object();
          private int max;
          private int lenght; 
          private ProgressBar progressbar1; 
          public Buffer(ProgressBar r)
          {
              this.progressbar1 = r; 
              this.max = 10;
              this.lenght = Toys.Count; 
  
          }
          public void writeMethod(Toy toy)
          {
              lock (MyLock)
              {
                 if (Toys.Count == max)
                 {
                     Monitor.Wait(MyLock); 
                 }
  
                 Toys.Enqueue(toy); 
                 Monitor.PulseAll(MyLock);  
                  progressbar1.Invoke(new Display(Disp), new object[] {Toys.Count, progressbar1});
                  MessageBox.Show("Que contains these items" + lenght); 
  
              }
  
          }
  
          public void readMethod()
          {
              lock (MyLock)
              {
                  if(Toys.Count == 0)
                  {
                      Monitor.Wait(MyLock); 
                  }
                  Toys.Dequeue(); 
                  Monitor.PulseAll(MyLock); 
              }
  
          }
          public void Disp(int I, ProgressBar l)
          {
              progressbar1.Value = I; 
  
  
          }
      }
    }
  </code></pre>