title: Recursion with Tasks and WaitAll
body: <p>Basically here is the problem, I have a function "GetAllCandidates" that accepts a list, calculates something, alters the parameters and calls itself using Task.Factory.StartNew to calculate all possible outputs with different morphs of the original array.</p>
  
  <pre><code>    private void GetAllCandidates(List&lt;int&gt; values)
      {
          Interlocked.Increment(ref _count);
  
          for (var i = values.Count - 1; i &gt;= 1; i --)
          {
             //Do work and calculations
  
             Task.Factory.StartNew(
                             () =&gt; GetAllCandidatePowers(newPowers)
             );
          }
      }
  </code></pre>
  
  <p>I need to fully utilize the cores on my CPU and wait for all tasks to finish, and here is the problem.</p>
  
  <ul>
  <li>If I call .Wait() for the task, my cores don't get utilized (CPU usage is very low), therefore the calculations don't finish quickly.</li>
  <li>Creating a global list for tasks and then calling WaitAll doesn't work because its a random recursive calls, the list of tasks isn't fully populated when my program reaches the call for WaitAll(), and also since the calculations are huge, I get an OutOfMemoryException when I try add my tasks to a global task list.</li>
  </ul>
  
  <p>any hints, on how to proceed with such a problem?</p>