title: C# async doesn't await
body: <p>The app I'm working on is supposed to retrieve a json string with the http client after which it gets deserialised and used in the app.</p>
  
  <p>Everything works, except for the await functionality. I'm doing something wrong and I can't seem to figure out what. How can I make sure that my DataService class waits untill I have my json and it has been deserialized?</p>
  
  <p>The DataService class:</p>
  
  <pre><code>class DataService : IDataService
  {
      private IEnumerable&lt;Concert&gt; _concerts;
  
      public DataService()
      {
          _concerts = new DataFromAPI()._concerts;
  
          Debug.WriteLine("____Deserialization should be done before continuing____");
  
          **other tasks that need the json**
  
      }
  }
  </code></pre>
  
  <p>My http client class:</p>
  
  <pre><code>class DataFromAPI
  {
  
      public IEnumerable&lt;Concert&gt; _concerts { get; set; }
  
      public DataFromAPI()
      {
          Retrieve();
      }
  
      public async Task Retrieve()
      {
          try
          {
              HttpClient client = new HttpClient();
              HttpRequestMessage request = new HttpRequestMessage();
              var result = await client.GetAsync(new Uri("http://url-of-my-api"), HttpCompletionOption.ResponseContentRead);
              string jsonstring = await result.Content.ReadAsStringAsync();
              DownloadCompleted(jsonstring);
          }
          catch {}
  
      }
  
      void DownloadCompleted(string response)
      {
          try
          {
              _concerts = JsonConvert.DeserializeObject&lt;IEnumerable&lt;Concert&gt;&gt;(response.ToString());
  
          }
          catch {}
      }
  }
  </code></pre>
  
  <p><strong>solution</strong></p>
  
  <p>After a lot of trial and error I realised that for this particular thingy it didn't have to be async, so I just recreated is on the main thread, with success:</p>
  
  <p>The DataService class:</p>
  
  <pre><code>class DataService : IDataService
  {
      private IEnumerable&lt;Concert&gt; _concerts;
  
      public DataService()
      {
          _concerts = new DataFromAPI()._concerts;
      }
  }
  </code></pre>
  
  <p>My http client class:</p>
  
  <pre><code>public static class DataFromAPI
  { 
      public void Retrieve()
      {
          try
          {
              HttpClient client = new HttpClient();
              HttpRequestMessage request = new HttpRequestMessage();
              var result = client.GetAsync("http://url-of-my-api").Result;
              if (result.IsSuccessStatusCode)
              {
                  var responseContent = result.Content;   
              }
              DownloadCompleted(result.Content.ReadAsStringAsync().Result);
          }
          catch {}
      }
  }
  </code></pre>