title: Async/Await with RestSharp in Windows Phone 8
body: <p>I did search this all over the internet, there are solutions for Windows Phone 7 but they don't work with Windows Phone 8 so please help me out with what I'm doing wrong. I'm writing a WP8 app that consumes an API from Mashape. I'm using the RestSharp NuGet package. Here are my extension methods for RestSharp packages to await.</p>
  
  <pre><code>public static class RestClientExtensions
  {
      public static Task&lt;IRestResponse&gt; ExecuteTaskAsync(this RestClient @this, RestRequest request)
      {
          if (@this == null)
              throw new NullReferenceException();
  
          var tcs = new TaskCompletionSource&lt;IRestResponse&gt;();
  
          @this.ExecuteAsync(request, (response) =&gt;
          {
              if (response.ErrorException != null)
                  tcs.TrySetException(response.ErrorException);
              else
                  tcs.TrySetResult(response);
          });
  
          return tcs.Task;
      }
  
      public static Task&lt;T&gt; ExecuteTaskAsync&lt;T&gt;(this RestClient @this, RestRequest request) where T : new()
      {
          if (@this == null)
              throw new NullReferenceException();
  
          var tcs = new TaskCompletionSource&lt;T&gt;();
  
          @this.ExecuteAsync&lt;T&gt;(request, (response) =&gt;
          {
              if (response.ErrorException != null)
                  tcs.TrySetException(response.ErrorException);
              else
                  tcs.TrySetResult(response.Data);
          });
  
          return tcs.Task;
      }
  }
  </code></pre>
  
  <p>Here is the function in which it is being called. The function lies in a API.cs class file.</p>
  
  <pre><code>public async Task&lt;SendMessage&gt; SendMessage(String phone, String msg, TextBox textBox)
  {
      // Create a POST request with the required headers &amp; parameters
      var request = new RestRequest("sendsms/{api}.json", Method.POST);
      request.AddUrlSegment("api", apiKey);
      request.AddHeader("X-Mashape-Key", "abcdefghixyz");
      request.AddParameter("msg", msg);
      request.AddParameter("phone", phone);
  
      var temp = await client.ExecuteTaskAsync&lt;SendMessage&gt;(request);
      return temp;
  }
  </code></pre>
  
  <p>Here is finally the Page1.xaml.cs file where all of this is needed.</p>
  
  <pre><code>private void appBarButton_Send_Click(object sender, EventArgs e)
  {
      Api api = new Api();
      SendMessage a = api.SendMessage(contactNumber, textBox_Message.Text, textBox_Message).Result;
      MessageBox.Show(a.message);
  }
  </code></pre>
  
  <p>If I directly call the RestSharp .ExecuteAsync() method in SendMessage() method it works fine. If I do it this way, it executes up till the await condition, returns the tcs.Task and then the complete app just halts. It stays that way and nothing changes. Any idea what I am doing wrong?</p>