title: Dequeueing objects from a ConcurrentQueue in C#
body: <p>Hey, I'm trying to implement a ConcurrentQueue in C# for an asynchronous server.  Items are being queued as soon as a complete message is received.  To dequeue messages, I'm making a small number of threads to do the work of dequeueing and servicing the requests.  This is inadequate as each thread is using a while loop, which consumes rather a large amount of processor time, for obvious reasons.</p>
  
  <p>Would anyone know of a method of dequeueing messages when required but not consuming so much processing time.</p>
  
  <pre><code>{
      ...
  
      for (int i = 0; i &lt; 3; i++)
      {
          Thread t = new Thread(new ThreadStart(startParsingMessages));
          t.Start();
      }
  
      ...
  }
  
  private void startParsingMessages()
  {
      QueueContainer dequeued = null;
      Console.WriteLine("Trying");
      while (true)
      {
          if (queue.TryDequeue(out dequeued))
          {
              Console.WriteLine("processing queue");
              ProcessMessage(dequeued.socket, dequeued.message);
          }
      }
  }
  </code></pre>