title: Async / Await chain hangs or deadlocks
body: <p>I have a Universal App that updates several objects from an internet source. In order to update the progress indicator and prevent duplicate requests I have the following logic.</p>
  
  <p>On refresh button:</p>
  
  <pre><code>foreach (var package in Packages.Where(item =&gt; !item.Received)) 
  {
      RefeshPackage(package);
  }
  </code></pre>
  
  <p>Which calls RefreshPackage for each package in the list:</p>
  
  <pre><code>private async Task RefeshPackage(PackageModel package)
  {
      if (Tasks.Contains(package.Id)) return;    
      Tasks.Add(package.Id);
  
      await DownloadAndUpdate(package);
  
      Tasks.Remove(package.Id);
      Refresh.RaiseCanExecuteChanged();
  }
  </code></pre>
  
  <p>Which calls DownloadAndUpdate for each package:</p>
  
  <pre><code>private async Task DownloadAndUpdate(PackageModel package)
  {
      var response = await webService.GetPackageStages(package.Id);
      if (response != null)
      {
          switch (response.Status)
          {
              case 200:
                  package.UpdateStages(response.Stages);
                  break;
  
              case 500:
                  //package doesn't exist or website down
                  break;
  
              default:
                  break;
          }
      }
      else
      {
          //no network / timed out
      }
  }
  </code></pre>
  
  <p>Which calls GetPackageStages for each package:</p>
  
  <pre><code>public async Task&lt;ResponseData&gt; GetPackageStages(string id)
  {
      var requestUri = string.Concat(MyUri, id);
  
      var client = new HttpClient();
      client.Timeout = new TimeSpan(0,0,5);
  
      try
      {
          var response = await client.GetAsync(requestUri);
          if(response.StatusCode == System.Net.HttpStatusCode.OK)
          {
              //process response
          }
      catch (Exception e)
      {
          return null;
      }
      finally
      {
          client.Dispose();
      }
  }
  </code></pre>
  
  <p>The hanging/deadlocking happens always in the last function, in the line:</p>
  
  <pre><code>await client.GetAsync(requestUri);
  </code></pre>
  
  <p>Sometimes it hangs here forever sometimes it works just fine. I've read a whole lot of other answers here regarding deadlocking and the common solutions are <em>using async/await all the way</em> (which I am already doing) or using <em>.ConfigureAwait(false)</em> also everywhere (which I already did with no success).</p>
  
  <p>Is there something else I'm missing or should I structure my code a different way? I've ran out of ideas/solutions. Any help would be appreciated.</p>