title: Task.Factory.ContinueWhenAny continue when any task finish without exception
body: <p>I have 3 tasks in my application that are responsible for getting data from databases.<br/>
  Till now I had all tasks executed one after one. If first finished and had Result then this was my data, if now I started second task and I checked again.</p>
  
  <p>Recently I found information that I can start multiple tasks and continue when one of them finish using <code>Task.Factory.ContinueWhenAny</code>. This works fine if all my task don't throw any Exceptions, but if any Task fails I can't get results I want.</p>
  
  <p>For example:</p>
  
  <pre><code>var t1 = Task.Factory.StartNew(() =&gt;
  {
      Thread.Sleep(5000);
      return 1;
  });
  
  var t2 = Task.Factory.StartNew(() =&gt;
  {
      Thread.Sleep(2000);
      throw new Exception("My error");
      return 2;
  });
  
  var t3 = Task.Factory.StartNew(() =&gt;
  {
      Thread.Sleep(4000);
      return 3;
  });
  
  Task.Factory.ContinueWhenAny(new[] {t1, t2,t3}, (t) =&gt;
  {
      Console.WriteLine(t.Result);
  });
  </code></pre>
  
  <p>This code starts 3 tasks and waits till one of them finish.
  Because <code>t2</code> throws exception after 2 seconds it is the one that is available in <code>ContinueWhenAny</code>.</p>
  
  <p>From code above I would like to get 3 in <code>t.Result</code>.<br/>
  Is there an option to continue only when task finished successfully? Something like <code>Task.Factory.ContinueWhenAnyButSkipFailedTasks</code></p>
  
  <p><strong>EDIT 1</strong>
  This is my solution for now based on @Nitram answer:</p>
  
  <pre><code>var t1 = Task.Factory.StartNew(() =&gt;
  {
      var rnd = new Random();
      Thread.Sleep(rnd.Next(5,15)*1000);
      throw new Exception("My error");
      return 1;
  });
  
  var t2 = Task.Factory.StartNew(() =&gt;
  {
      Thread.Sleep(2000);
      throw new Exception("My error");
      return 2;
  });
  
  var t3 = Task.Factory.StartNew(() =&gt;
  {
      throw new Exception("My error");
      return 3;
  });
  
  var tasks = new List&lt;Task&lt;int&gt;&gt; { t1, t2, t3 };
  
  Action&lt;Task&lt;int&gt;&gt; handler = null;
  
  handler = t =&gt;
  {
      if (t.IsFaulted)
      {
          tasks.Remove(t);
          if (tasks.Count == 0)
          {
              throw new Exception("No data at all!");
          }
          Task.Factory.ContinueWhenAny(tasks.ToArray(), handler);
      }
      else
      {
          Console.WriteLine(t.Result);
      }
  };
  
  Task.Factory.ContinueWhenAny(tasks.ToArray(), handler);
  </code></pre>
  
  <p>What I need now is how to throw exception when all tasks throw exception?<br>
  Maybe this can be changed into single method that would return task - something like child tasks?</p>