title: Multiple Async Methods, best to use WhenAll with different return types
body: <p>I have an Async controller action method which calls 4 async methods on my Backend to return List from each.  The List of objects is different for each method. ie List List etc.</p>
  
  <p>I have this working as so:</p>
  
  <pre><code>BizProvider bp = new BizProvider();
  List&lt;biz.Customer&gt; custReturn = await bp.GetCustomerAsync();
  List&lt;biz.Account&gt; acctReturn = await bp.GetAccountAsync();
  ...plus 2 more
  List&lt;object&gt; returnArr = new List&lt;object&gt;();
  returnArr.Add(custReturn);
  returnArr.Add(acctReturn);  ...plus 2 more
  return JsonConvert.SerializeObject(returnArr);
  </code></pre>
  
  <p>Should I use <code>Task.WhenAll</code> because of multiple Tasks?</p>
  
  <p>The example at the microsoft
  <a href="https://msdn.microsoft.com/en-us/library/hh194874%28v=vs.110%29.aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/hh194874%28v=vs.110%29.aspx</a></p>
  
  <p>All the Tasks return <code>List&lt;int&gt;</code></p>
  
  <p>So I used and abstract class and had all my list object types inherit from this.
  and I changed the return type of my business object provider to return the List of abstract type
  so now I can do:</p>
  
  <pre><code>var tasks1 = new List&lt;Task&lt;List&lt;Biz.AbstractClass&gt;&gt;&gt;();
  tasks1.Add(bp.GetCustomerAsAbstractAsync());
  tasks1.Add(bp.GetAccountAsAbstractAsync());
  ...plus 2 more
  </code></pre>
  
  <p>I then call
      var continuation = Task.WhenAll(tasks1);</p>
  
  <p>this executes then the next line it gets to the <code>.Results</code> but then stops executing???</p>
  
  <pre><code>foreach (var result in continuation.Result)
                                         ^ stops here
  </code></pre>
  
  <p>further on I call </p>
  
  <pre><code>returnArrays.Add(result1);
  return JsonConvert.SerializeObject(returnArrays);
  </code></pre>
  
  <p>but these never get hit...I don't know why.
  Perhaps I don't need a <code>WhenAll</code>, but then I am still curious what is going wrong.
  perhaps I need an await on the specific functions, or invoke the Action somehow, as in the Microsoft link the functions are called inline.</p>
  
  <pre><code>Task.Run(async () =&gt; { x=x,etc...)
  </code></pre>
  
  <p>Edit 20150306 => adding more implementation details</p>
  
  <pre><code>CustMan cm = new CustMan(); 
  List&lt;object&gt; returnArr = new List&lt;object&gt;();
  var aTask = cm.GetCustomersAsync(); 
  var bTask = cm.GetAccountsAsync(); 
  await Task.WhenAll(aTask, bTask);  
  returnArr.Add(aTask.Result);//same for bTask &lt;-- breakpoint never hits 
  return JsonConvert.SerializeObject(returnArr); 
  //also .js ajax return method never comes back.
  
  //in CustMan()
  public async Task&lt;List&lt;biz.Customer&gt;&gt; GetCustomersAsync() {
      List&lt;biz.Customer&gt; custList = await (from contact in ObjectContextDb.GetData&lt;da.ContactInfo&gt;()//&lt;--generic returns IQueryable
       join customerContact in ObjectContextDb.GetData&lt;da.CustomerContact&gt;() on contact.Id equals customerContact.ContactInfoID
       join customerOrg in ObjectContextDb.GetData&lt;da.CustomerOrganisation&gt;() on customerContact.OrgID equals customerOrg.Id
       orderby contact.LastName
       select new biz.Customer {
         CustomerContactInfo = new biz.Contact() {
           ID = contact.Id,
           WorkPhone = contact.WorkPhone
         },
         CustomerOrg = new biz.CustomerOrganisation {
           ID = facultyOrg.Id,
           Name = facultyOrg.OrgName,
           ClientID = (customerContact.ClientID.HasValue ? customerContact.ClientID.Value : 0)
         }
       }).ToListAsync&lt;biz.Customer&gt;();
      return custList;// &lt;-- Breakpoint hits here, the List has items
  }
  
  public async Task&lt;List&lt;biz.Account&gt;&gt; GetAccountsAsync()
  {
   var roles = (from acctType in ObjectContextDb.GetData&lt;da.AccountInType&gt;()
    join r in ObjectContextDb.GetData&lt;da.AccountType&gt;() on acctType.AccountTypeID equals r.ID
    select new
    {
     AccountId = acctType.AccountID,
     Type = r.TypeName
    });   //.ToList();
  
    List&lt;biz.Account&gt; allContacts = await (from account in ObjectContextDb.GetData&lt;da.Account&gt;()
         orderby account.Name
         select new biz.Account()
         {
           Number = account.Id,
           Name = account.Name,
           Roles = (from r in roles where account.Id == r.AccountId select r.Type).ToList()
         }).ToListAsync&lt;biz.Account&gt;();
  
    return allContacts;//  &lt;-- Breakpoint hits here, the List has items
  }
  </code></pre>
  
  <p>The method which calls the Manager Class methods without <code>WhenAll</code> works!</p>
  
  <pre><code>CustMan cm = new CustMan(); 
  List&lt;object&gt; returnArrays = new List&lt;object&gt;();
  List&lt;biz.Customer&gt; custReturn = await cm.GetCustomersAsync();
  List&lt;biz.Account&gt; acctReturn = await cm.GetAccountsAsync();
  
  returnArrays.Add(custReturn);
  returnArrays.Add(acctReturn);
  
  return JsonConvert.SerializeObject(returnArrays);
  </code></pre>