title: How to return a Task<T> in an async method
body: <p>I have this method in my Windows Phone 8 app where I get some data from a url    </p>
  
  <pre><code>   public async static Task&lt;byte[]&gt; getData(string url)
      {
      HttpClient client = null;
      HttpResponseMessage response = null;
      Stream stream = null;
      byte[] dataBytes = null;
      bool error = false;
  
      try
      {
          Uri uri = new Uri(url);
  
          client = new HttpClient();
          response = await client.GetAsync(uri);
          response.EnsureSuccessStatusCode();
  
          stream = await response.Content.ReadAsStreamAsync();
          dataBytes = getDataBytes(stream); 
  
          if (dataBytes == null)
          {
              error = true;
          }
          else if (dataBytes.Length == 0)
          {
              error = true;
          }
      }
      catch (HttpRequestException )
      {
      }
  
      if (error)
      {
          return getData(url); // this is where the issue is
      }
  
      return dataBytes;
      }
  </code></pre>
  
  <p>But since the method is an async one, the return type cannot be a Task, like I have done on the line <code>return getData(url);</code> since <code>getData(string)</code> returns Task. Any ideas on how I can rewrite this to make it work?</p>