title: C# threading for processing message queue
body: <p>I have the following requirements -</p>
  
  <ol>
  <li>A thread which receives the messages and en-queue those.</li>
  <li>A thread which processes the enqueued messages.</li>
  </ol>
  
  <p>Now, the second thread always has to be alive - for which I have used infinite while loop as follows:</p>
  
  <pre><code>private AutoResetEvent messageReset;
  private Queue&lt;byte[]&gt; messageQueue;
  
  //thread 2 method
  private void ProcessIncomingMessages()
  {
   messageReset.WaitOne(); //wait for signal
   while(true)
   {
      if (messageQueue.Count &gt; 0)
      {
          //processing messages
      }
    }
  }
  public void SubmitMessageForProcessing(byte[] message){
              messageQueue.Enqueue(message); //enqueue message
  
              // Release the thread
              messageReset.Set();
  }
  </code></pre>
  
  <p>Now, this infinite while loop is shooting the CPU utilization very high. 
  Is there any workaround to lower down the CPU utilization</p>
  
  <p>NOTE: I can't add any thread.sleep statement as the incoming messages are to be displayed on UI with minimum delay.</p>