title: C# Task.WaitAll() Cancelation with Error handling
body: <p>I have a problem.
  I try to run multiple long running tasks. If one fails I wanna cancel all other tasks and get the failure exception.
  The example given below.
  I wanna catch AggregateException with Exception thrown by </p>
  
  <pre><code> throw new Exception("FailureTask");
  </code></pre>
  
  <p>But instead of  AggregateException I am catching OperationCanceledException, because I wanna cancel all other task.</p>
  
  <pre><code>    [TestMethod]
      public void TestParallelTaskCancelation()
      {
          var cancellationTokenSource = new CancellationTokenSource();
          Task[] tasks =
          {
              Task.Factory.StartNew(DummyTask, cancellationTokenSource, cancellationTokenSource.Token),
              Task.Factory.StartNew(DummyTask, cancellationTokenSource, cancellationTokenSource.Token),
              Task.Factory.StartNew(DummyTask, cancellationTokenSource, cancellationTokenSource.Token),
              Task.Factory.StartNew(DummyTask, cancellationTokenSource, cancellationTokenSource.Token),
              Task.Factory.StartNew(FailureTask, cancellationTokenSource, cancellationTokenSource.Token)
          };
  
          try
          {
              Task.WaitAll(tasks, cancellationTokenSource.Token);
          }
          catch (OperationCanceledException e)
          {
              Console.WriteLine(e.GetaAllMessages());
          }
          catch (AggregateException e)
          {
              Console.WriteLine(e.GetaAllMessages());
          }
      }
  
      private void DummyTask(object o)
      {
          var cancellationToken = (CancellationTokenSource)o;
          while (true)
          {
              Thread.Sleep(10000);
              if (cancellationToken.IsCancellationRequested)
              {
                  cancellationToken.Token.ThrowIfCancellationRequested();
              }
          }
      }
  
      private void FailureTask(object o)
      {
          var cancellationToken = (CancellationTokenSource)o;
  
          var executionTask = Task.Factory.StartNew(() =&gt;
          {
              Thread.Sleep(1000);
              throw new Exception("FailureTask");
          }, cancellationToken.Token);
  
          executionTask.ContinueWith(t =&gt;
          {
              cancellationToken.Cancel(false);
              throw new Exception(t.Exception.GetaAllMessages());
          }, TaskContinuationOptions.OnlyOnFaulted);
  
          if (executionTask.Wait(10 * 1000, cancellationToken.Token)) return;
          //timeout !!!
          throw new Exception("The limit 'Max Seconds Per Query' has been exceeded!!!");
      }`
  </code></pre>
  
  <p>Please help.</p>