Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would be willing to bet the answer to Execute returning a thread-safe <code>IEnumerator</code> implementation is highly unlikely. That said, this sounds like yet another case for the <a href="http://en.wikipedia.org/wiki/Producer-consumer_problem" rel="nofollow">producer-consumer pattern</a>.</p> <p>In your specific scenario I would have the original thread that called Execute read the results off sequentially and stuff them into a <a href="http://msdn.microsoft.com/en-us/library/dd267312.aspx" rel="nofollow"><code>BlockingCollection&lt;T&gt;</code></a>. Before you start doing that though, you want to start a separate <code>Task</code> that will control the consumption of those items using <code>Parallel::ForEach</code>. Now, you will probably also want to look into using the <code>GetConsumingPartitioner</code> method of the ParallelExtensions library in order to be most efficient since the default partitioner will create more overhead than you want in this case. You can read more about this from <a href="http://blogs.msdn.com/b/pfxteam/archive/2010/04/06/9990420.aspx" rel="nofollow">this blog post</a>.</p> <p>An added bonus of using <code>BlockingCollection&lt;T&gt;</code> over a raw <code>ConcurrentQueueu&lt;T&gt;</code> is that it offers the ability to <a href="http://msdn.microsoft.com/en-us/library/dd460690.aspx" rel="nofollow">set bounds</a> which can help block the producer from adding more items to the collection than the consumers can keep up with. You will of course need to do some performance testing to find the sweet spot for your application.</p>
 

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