title: RabbitMQ only processes 50 messages then blocks
body: <p>I am using RabbitMQ in .net and I am seeing a weird issue when I drop 100 messages on the queue. It processes approximately 50 messages, then the <code>Dequeue()</code> method just hangs. If I restart the service, it processes the remaining items.</p>
  
  <p><strong>EDIT: It is processing exactly 50% of the queue. When I add 1000 messages, it only processes 500. Even when single threaded</strong></p>
  
  <p>What am I missing here?</p>
  
  <pre><code>    private void InitializeAgent() {
          var agentFactory = new ConnectionFactory() { HostName = "localhost" };
          agentConnection = agentFactory.CreateConnection();
          agentChannel = agentConnection.CreateModel();
          var ok = agentChannel.QueueDeclare(GetType().Name, true, false, false, null);
          consumer = new QueueingBasicConsumer(agentChannel);
          agentChannel.BasicConsume(GetType().Name, false, consumer);
      }
  
      public void DequeueMessages() {
          ThreadPool.SetMaxThreads(200, 200);
          ThreadPool.SetMinThreads(200, 200);
          var ea = consumer.Queue.Dequeue();
          ThreadPool.QueueUserWorkItem(ProcessWorkInThread, ea);
      }
  
      public void AgentTask() {
          var instance = factory.GetInstance(threadItem);
  
          while (true) 
              DequeueMessages();
      }
  
      private void ProcessWorkInThread(object state) {
           var ea = state as BasicDeliverEventArgs;
  
           var message = Encoding.UTF8.GetString(ea.Body);
  
           var settings = new JsonSerializerSettings();
           settings.ContractResolver = new DefaultContractResolver() { DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public };
           var item = JsonConvert.DeserializeObject&lt;TEntity&gt;(message, settings);
  
           Thread.Sleep(10000) //simulate work
           lock (agentChannel)             
               agentChannel.BasicAck(ea.DeliveryTag, false);            
       }
  </code></pre>