title: Use an async callback with Task.ContinueWith
body: <p>I'm trying to play a bit with C#'s async/await/continuewith.
  My goal is to have to have 2 tasks which are running in parallel, though which task is executing a sequence of action in order.
  To do that, I planned to have a <code>List&lt;Task&gt;</code> that represent the 2 (or more) tasks running in parallel, and to use <code>ContinueWith</code> on each of the <code>Task</code>
  My problem is that the callback in continue with seems not to be executed while the <code>await taskList</code> has already returned.</p>
  
  <p>In order to summarize, here's a sample to illustrate what I'm expecting to happen:</p>
  
  <pre><code>class Program
  {
      static public async Task Test()
      {
          System.Console.WriteLine("Enter Test");
          await Task.Delay(100);
          System.Console.WriteLine("Leave Test");
      }
  
      static void Main(string[] args)
      {
          Test().ContinueWith(
          async (task) =&gt;
          {
              System.Console.WriteLine("Enter callback");
              await Task.Delay(1000);
              System.Console.WriteLine("Leave callback");
          },
          TaskContinuationOptions.AttachedToParent).Wait();
          Console.WriteLine("Done with test");
      }
  }
  </code></pre>
  
  <p>The expected output would be</p>
  
  <pre><code>Enter Test
  Leave Test
  Enter callback
  Leave callback
  Done with test
  </code></pre>
  
  <p>However, the output is </p>
  
  <pre><code>Enter Test
  Leave Test
  Enter callback
  Done with test
  </code></pre>
  
  <p>Is there a way to make the Task on which <code>ContinueWith</code> is called wait for the provided function to complete before being considered as done? ie. .Wait will wait for both tasks to be completed, the original one, and the one which is returned by ContinueWith</p>