Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, parallelization often doesn't make sense in ASP.NET. If you have many users accessing your site, you usually care more about scalability (how many users can you serve at the same time), than raw performance for single user.</p> <p>If that's not your case, parallelization might make sense for you.</p> <p>Second, you're getting that error, because <code>Parallel.ForEach()</code> is not a loop (as far as the language is concerned). And <code>break</code>ing out of a lambda doesn't make any sense.</p> <p>To break out of <code>Parallel.ForEach()</code>, you can use <a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallelloopstate.break.aspx" rel="nofollow"><code>ParallelLoopState.Break()</code></a> or <a href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.parallelloopstate.stop.aspx" rel="nofollow"><code>ParallelLoopState.Stop()</code></a> (read the documentation to find out which one of those do you actually want). To do this, you will need to use an overload of <code>Parallel.ForEach()</code> that gives you that <code>ParallelLoopState</code>.</p> <p>Third, there is a good reason why <code>Parallel.ForEach()</code> doesn't support <code>ArrayList</code>: it's because you should never use it. If you really want a list of <code>object</code>s, use <code>List&lt;object&gt;</code> to make it clear that you really don't know the type. If you can't (or don't want to) change the <code>ArrayList</code>, you can use <code>.Cast&lt;object&gt;()</code> to make <code>Parallel.ForEach()</code> (and other methods that work with <code>IEnumerable&lt;T&gt;</code>) accept it.</p> <p>Fourth, I think that parallelizing just the <code>ProcessRecord</code> doesn't make sense. It looks like <code>status</code> returns the status for the last <code>ProcessRecord</code>. And if you execute <code>ProcessRecord</code> in parallel, then it's not clear anymore which one is the last.</p> <p>Also, you shouldn't <em>think</em> that some method is not thread-safe. You should know that. If you parallelize something that you don't know is thread-safe, you're likely to get hard to debug bugs later on.</p> <p>Fifth, if you want to parallelize just the first part of a loop, I think the best option is PLINQ. Something like:</p> <pre><code>var intermediateResults = source.AsParallel().Select(x =&gt; Process(x)); foreach (var intermediateResult in intermediateResults) { // the rest of the loop } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload