title: Wait all tasks with some conditions
body: <p>I am writing some complex tasks and I can't do success to solve the problem.</p>
  
  <ol>
  <li>I open some tasks for searching some data asynchronously.</li>
  <li>At the end I wait for all tasks.</li>
  <li>I want to run on all the data and does not stop the tasks until they all finish.
  But, when one of the tasks finds some relevant data, I want to continue with the code that is after the wait all tasks, but at the same time, I want to continue searching with my tasks (until all the data will be read).</li>
  </ol>
  
  <p><a href="https://stackoverflow.com/questions/11824755/how-to-wait-tasks-with-conditions">Here</a> I found a way how to continue the code after the wait all if one of the tasks finds the data, the problem is that it also stops all tasks from running.</p>
  
  <p>Here is my code (this  is just code for demonstration of the problem).</p>
  
  <pre><code>private static void RunTasks()
  {
      TaskCompletionSource&lt;bool&gt; tcs = new TaskCompletionSource&lt;bool&gt;();
      Task&lt;bool&gt; t0 = Task.Factory.StartNew&lt;bool&gt;(() =&gt; Find(1, 2));
      Task&lt;bool&gt; t1 = Task.Factory.StartNew&lt;bool&gt;(() =&gt; Find(4, 7));
      Task&lt;bool&gt; t2 = Task.Factory.StartNew&lt;bool&gt;(() =&gt; Find(13, 14));
  
      t0.ContinueWith(_ =&gt;
      {
          if (t0.Result)
              tcs.TrySetResult(t0.Result);
      });
  
      t1.ContinueWith(_ =&gt;
      {
          if (t1.Result)
              tcs.TrySetResult(t1.Result);
      });
  
      t2.ContinueWith(_ =&gt;
      {
          if (t2.Result)
              tcs.TrySetResult(t2.Result);
      });
  
      tcs.Task.Wait();
  
      Console.WriteLine("Found");
      ContinueWork(); //Runs after at least one data found or when all tasks finish.
  }
  
  //Just for demonstration...
  private static bool Find(int a, int b)
  {
      Console.WriteLine("a: " + a + " b: " + b);
      return a == 4 &amp;&amp; b == 7 ? true : false;
  }
  </code></pre>
  
  <p>How can I write it so that when some data is found it will continue to ContinueWork method and also will continue with reading the data with the tasks?</p>
  
  <p>Thanks.</p>