title: Async Await In Linq .TakeWhile
body: <p>I am trying to convert my foreach function to a linq function</p>
  
  <p>here is my normal code [Works fine]</p>
  
  <pre><code>    var tList = new List&lt;Func&lt;Task&lt;bool&gt;&gt;&gt; { Method1, Method2 };
      tList.Shuffle();
  
      int succeed = 0;
      foreach (var task in tList)
      {
          var result = await task();
  
          if(!result)
              break;
  
          succeed += 1;
      }
  
      MessageBox.Show(succeed == 1 ? "Loading complete." : "Something went wrong!");
  </code></pre>
  
  <p>And here is after converted to Linq [Giving 2 compiler errors]</p>
  
  <pre><code>    var tList = new List&lt;Func&lt;Task&lt;bool&gt;&gt;&gt; { Method1, Method2 };
      tList.Shuffle();
  
      int succeed = tList.Select(async task =&gt; await task()).TakeWhile(result =&gt; result).Count();
  
      MessageBox.Show(succeed == 1 ? "Loading complete." : "Something went wrong!");
  </code></pre>
  
  <p>Errors</p>
  
  <blockquote>
    <ul>
    <li>Cannot convert lambda expression to delegate type    'System.Func,bool>' because some of 
    the return types in the block are not implicitly convertible to the<br>
    delegate return type</li>
    <li>Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'bool'</li>
    </ul>
  </blockquote>
  
  <p>I wonder why the compiler is giving those messages, so any help will be appreciated.</p>
  
  <p>Note : i also tried <code>.TakeWhile(async result =&gt; await result)</code> with that error</p>
  
  <blockquote>
    <ul>
    <li>The return type of an async method must be void, Task, or Task T</li>
    </ul>
  </blockquote>
  
  <p>Method1 and Method2 if someone wanna them :</p>
  
  <pre><code>public async Task&lt;bool&gt; Method1()
  {
      await Task.Delay(1000);
      Console.WriteLine("Method1");
      return false;
  }
  
  public async Task&lt;bool&gt; Method2()
  {
      await Task.Delay(1000);
      Console.WriteLine("Method2");
      return true;
  }
  </code></pre>