title: Read data from NetworkStream without heavy loop
body: <p>I'm reading data from a TcpClient/NetworkStream in a loop that looks like this:</p>
  
  <pre><code>while (true)
  {
      byte[] answer = new byte[1000];
      int count = m_networkStream.Read(answer, 0, 1000);
      if (count &gt; 0)
      {
          ...
      }
  }
  </code></pre>
  
  <p>The bad thing is that the <code>Read()</code> returns immediately 0 when no data is available. The wrapping <code>TcpClient</code> does not have a <code>Select()</code> method or similar that would stop until some data arrives. So I have a tight loop eating up huge amounts of CPU time.</p>
  
  <p>So... how can this be done better? Is there a way to <em>suspend</em> the thread until data arrives or is there a <code>Read()</code> method that blocks?</p>
  
  <p>Thanks!</p>
  
  <p>To Editors: this is NOT a duplicate to the other, linked question! When you would not have edited (or better: damaged) my original question you would have been able to see this. The reason for the other question is a permanent loop for "data available", here reading of the data does not block/I'm looking for a method to do a select() on the socket.</p>