title: While loop without blocking console output
body: <p>I have been working on some multithreaded console applications recently and was wondering how to do this. I use this code to control the amount of threads created by the application:</p>
  
  <pre><code>foreach(string s in File.ReadAllLines("file.txt")){
      while (threads &gt;= maxThreads) ;
      Thread t = new Thread(() =&gt; { 
          threads++;
          //thread code - make network request using 's'
          Console.WriteLine("TEST");
          threads--;
          Thread.CurrentThread.Abort();
      });
      t.start();
  }
  </code></pre>
  
  <p>However, due to the while loop, the <code>Console.WriteLine</code> method in the created is blocked and does not show up until the next free thread is available.</p>
  
  <p>Is there any way I can prevent this while loop from blocking the <code>Console.WriteLine</code> call?</p>
  
  <p>EDIT - Reversed condition in while loop.</p>