title: Task.WaitAll not waiting on other async methods
body: <p>I'm asynchronously retrieving some rss articles with my Portable Class Library that uses the Microsoft.Bcl library (which doesn't have Task.WhenAll).  Each article has a url to rss comments that I need to asynchronously retrieve as well.  </p>
  
  <p>The code below is my library.  I call GetArticles() but it does not return any of the which creates a list of tasks that call GetComments() to asynchronously get the comments.</p>
  
  <p>I've tried using Task.WaitAll in GetArticles to wait for the comments but it does not block the thread.  Any help would be appreciated.</p>
  
  <pre><code>    private const string ArticlesUri = "";
  
      public async Task&lt;List&lt;ArticleBrief&gt;&gt; GetArticles()
      {
          var results = new List&lt;ArticleBrief&gt;();
          try
          {
              var wfw = XNamespace.Get("http://wellformedweb.org/CommentAPI/");
              var media = XNamespace.Get("http://search.yahoo.com/mrss/");
              var dc = XNamespace.Get("http://purl.org/dc/elements/1.1/");
  
              var t = await WebHttpRequestAsync(ArticlesUri);
              StringReader stringReader = new StringReader(t);
              using (var xmlReader = System.Xml.XmlReader.Create(stringReader))
              {
                  var doc = System.Xml.Linq.XDocument.Load(xmlReader);
                  results = (from e in doc.Element("rss").Element("channel").Elements("item")
                             select
                                 new ArticleBrief()
                                 {
                                     Title = e.Element("title").Value,
                                     Description = e.Element("description").Value,
                                     Published = Convert.ToDateTime(e.Element("pubDate").Value),
                                     Url = e.Element("link").Value,
                                     CommentUri = e.Element(wfw + "commentRss").Value,
                                     ThumbnailUri = e.Element(media + "thumbnail").FirstAttribute.Value,
                                     Categories = GetCategoryElements(e.Elements("category")),
                                     Creator = e.Element(dc + "creator").Value
                                 }).ToList();
  
              }
  
              var tasks = new Queue&lt;Task&gt;();
              foreach (var result in results)
              {
                  tasks.Enqueue(
                      Task.Factory.StartNew(async ()=&gt;
                          {
                              result.Comments = await GetComments(result.CommentUri);
                          }
                      ));
              }
  
              Task.WaitAll(tasks.ToArray());
          }
          catch (Exception ex)
          {
              // should do some other
              // logging here. for now pass off
              // exception to callback on UI
              throw ex;
          }
  
          return results;
      }
  
      public async Task&lt;List&lt;Comment&gt;&gt; GetComments(string uri)
      {
          var results = new List&lt;Comment&gt;();
          try
          {
              var wfw = XNamespace.Get("http://wellformedweb.org/CommentAPI/");
              var media = XNamespace.Get("http://search.yahoo.com/mrss/");
              var dc = XNamespace.Get("http://purl.org/dc/elements/1.1/");
  
              var t = await WebHttpRequestAsync(uri);
              StringReader stringReader = new StringReader(t);
              using (var xmlReader = System.Xml.XmlReader.Create(stringReader))
              {
                  var doc = System.Xml.Linq.XDocument.Load(xmlReader);
                  results = (from e in doc.Element("rss").Element("channel").Elements("item")
                             select
                                 new Comment()
                                 {
                                     Description = e.Element("description").Value,
                                     Published = Convert.ToDateTime(e.Element("pubDate").Value),
                                     Url = e.Element("link").Value,
                                     Creator = e.Element(dc + "creator").Value
                                 }).ToList();
              }
          }
          catch (Exception ex)
          {
              // should do some other
              // logging here. for now pass off
              // exception to callback on UI
              throw ex;
          }
  
          return results;
      }
  
      private static async Task&lt;string&gt; WebHttpRequestAsync(string url)
      {
          //TODO: look into getting 
          var request = WebRequest.Create(url);
          request.Method = "GET";
  
          var response = await request.GetResponseAsync();
          return ReadStreamFromResponse(response);
      }
  
      private static string ReadStreamFromResponse(WebResponse response)
      {
          using (Stream responseStream = response.GetResponseStream())
          using (StreamReader sr = new StreamReader(responseStream))
          {
              string strContent = sr.ReadToEnd();
              return strContent;
          }
      }
  
      private List&lt;string&gt; GetCategoryElements(IEnumerable&lt;XElement&gt; categories)
      {
          var listOfCategories = new List&lt;string&gt;();
  
          foreach (var category in categories)
          {
              listOfCategories.Add(category.Value);
          }
  
          return listOfCategories;
      }
  </code></pre>
  
  <p>Updated Code from Solution, just added .UnWrap() on the Enqueue method:</p>
  
  <pre><code>            var tasks = new Queue&lt;Task&gt;();
              foreach (var result in results)
              {
                  tasks.Enqueue(
                      Task.Factory.StartNew(async ()=&gt;
                          {
                              result.Comments = await GetComments(result.CommentUri);
                          }
                      ).Unwrap());
              }
  
              Task.WaitAll(tasks.ToArray());
  </code></pre>