title: ThreadPool callbacks in tight loop - 100% CPU
body: <p>I have a method in my algorithm that runs a very tight loop on a very large set of data.  I originally wrote it single-threaded which was fine, but it took a long time.  I am to the point now of wanting to speed it up, so I am now using ThreadPool to parallelize the work.  The problem is that this causes my CPU usage to go to 95-100%, which I sort of expected.  However, my performance has increased dramatically, but I think I could make it better if I could cut down on all the context switching.  This also causes my other programs to be a bit laggy since they have to fight the threads for CPU resources.</p>
  
  <p>My question is how should I go about doing this?  The only thing I've been able to think of is to limit the number of threads running at one time, but this may make my algorithm slower since only a few threads will be able to run at one time.  I don't want to add sleeps in my threads either since I just need the algorithm to run to completion as quickly as possible.</p>
  
  <p>EDIT:  Several people have mentioned using the TPL.  I think that is a great idea, but unfortunately I forgot to mention that I am stuck using .NET 3.5 since the parent application hasn't released a version using .NET 4 yet.</p>