How do I implement this parallel pattern in C#? <p>What I'm ultimately trying to accomplish is to get the HTML from an unknown but limited number of webpages where <code>GetPage(i)</code> returns the HTML for page <code>i</code> and I want to stop as soon as I found a non-page.</p> <p>The exact pattern I'm going for is like this: </p> <ul> <li>Start <code>N</code> parallel tasks that are <code>GetPage(0)</code>, ..., <code>GetPage(N-1)</code>. </li> <li>As soon as a task <code>GetPage(i)</code> completes, if the task was able to get the page, add it to a collection of pages and try to get the next largest page that hasn't tried to be processed yet; or if the task was not able to get the page, cancel all tasks <code>GetPage(j)</code> where <code>j&gt;i</code>.</li> </ul> <p>So my attempted implementation is like </p> <pre><code> var docs = new LinkedList&lt;HtmlDocument&gt;(); int tlimit = 20; var tasks = new Task&lt;HtmlDocument&gt;[tlimit]; for(int i = 0; i &lt; tlimit; ++i) { tasks[i] = Task&lt;HtmlDocument&gt;.Factory.StartNew(() =&gt; BoardScanner.GetBoardPage(i)); } /// ??? </code></pre>