title: Threadpool queue stalling on 10th item
body: <p>I'm having a problem with my test application.  I'm running a win form application which can post requests to a web service.  There is a timer which periodically adds items to the queue of requests.  I have a class called AutoManager which is used to pick items off the queue and send them off to the web service.</p>
  
  <p>In TryKickQueue() it adds an IAutoProcessor onto the threadpool queue.  Once the IAutoProcessor is finished it calls back to the AutoManager to remove itself from the queue.</p>
  
  <p>This works fine and runs the first 10 requests no problem however for some reason I can't figure out the 10th thread never finishes and so it gets stuck.  It's weird because it is always the 10th.  Am I doing something wrong, should I be cleaning things up?</p>
  
  <p>Should this happen or is it probably a deadlock that i've not been able to find?</p>
  
  <p>Many thanks
  Neil</p>
  
  <pre><code>    public AutoManager(Settings _settings, Log _log)
      {
          m_sessionKicker = new BackgroundWorker();
          m_sessionKicker.DoWork += SessionKickerDoWork;
          m_sessionKicker.RunWorkerCompleted += SessionKickerRunCompleted;
          m_sessionKicker.WorkerSupportsCancellation = true;
          m_sessionKicker.RunWorkerAsync();
  
          m_processorQueue = new List&lt;IAutoProcessor&gt;();
          m_inProcessingQueue = new List&lt;IAutoProcessor&gt;();
      }
  
      private void SessionKickerDoWork(object sender, DoWorkEventArgs e)
      {
          bool bFinished = false;
  
          while (!bFinished)
          {
              TryKickQueue();
          }
      }
  
      private void TryKickQueue()
      {
          object thisObject = new Object();
  
          lock (thisObject)
          {
              if (m_processorQueue.Count &gt; 0 &amp;&amp; m_inProcessingQueue.Count &lt; m_settings.MaxThreads)
              {
                  IAutoProcessor proc = m_processorQueue[0];
                  m_inProcessingQueue.Add(proc);
                  m_processorQueue.RemoveAt(0);
  
                  if (proc != null)
                  {
                      ThreadPool.QueueUserWorkItem(new WaitCallback(proc.SendData));
                  }
              }
          }
      }
  
      public void OnRemoveAutoProcessor(IAutoProcessor _autoProcessor)
      {
          object thisObject = new Object();
  
          lock (thisObject)
          {
              m_inProcessingQueue.Remove(_autoProcessor);
          }
      }
  </code></pre>