title: How to stop a Parallel.ForEach loop?
body: <p>I have this code to start a Parallel ForEach loop:</p>
  
  <pre><code>Parallel.ForEach&lt;ListViewItem&gt;(filesListView.Items.Cast&lt;ListViewItem&gt;(), new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, item =&gt; {
      if (CallToStop == true)
          {  
              //Code here to stop the loop!
          }        
      internalProcessStart(item);
  });
  </code></pre>
  
  <p>I have some code which will check if there is a call to stop the threads, and then I would like to <code>break;</code> the code, but this doesn't work with Parallel.</p>
  
  <p>I found the same <a href="https://stackoverflow.com/questions/12571048/break-parallel-foreach">question by someone else</a>, but their code is slighly different to mine, and I'm not sure where to put the <code>ParallelLoopState state</code>.</p>
  
  <p>Thanks!</p>