title: What is best way of iterating over Dictionary with multiple threads?
body: <p><strong>EDIT</strong> I'm limited to the .Net version 2.0 so I don't believe I can use the Task Parallel Library in this case.</p>
  
  <p>I've got a dictionary of objects.</p>
  
  <p>I need to iterate over all of them and perform an expensive, but embarrassingly parallelizable ,  calculation on each element.</p>
  
  <p>Currently I'm using a single thread to iterate over the entire dictionary.</p>
  
  <p>Approach 1</p>
  
  <blockquote>
    <p>I've toyed with using a thread pool to split the calculations over
    multiple threads but that leads to the question of how to pass this to
    separate threads?</p>
  </blockquote>
  
  <p>I currently convert the keys collection to an array and pass part of the array to separate threads so they can use the key to look up the value and perform the calculation.</p>
  
  <p>Approach 2</p>
  
  <blockquote>
    <p>Alternatively I could iterate over each key and dispatch a thread in
    a thread pool to each element.</p>
  </blockquote>
  
  <p>The second approach is slower.</p>
  
  <p>Is there a better alternative?</p>