How should I implement ExecuteAsync with RestSharp on Windows Phone 7?

前端 未结 6 1443
忘掉有多难
忘掉有多难 2020-12-08 04:50

I\'m attempting to use the documentation on the RestSharp GitHub wiki to implement calls to my REST API service but I\'m having an issue with the ExecuteAsync method in part

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 04:56

    As an alternative (or complement) to the fine answer by Gusten. You can use ExecuteTaskAsync. This way you do not manually have to handle TaskCompletionSource. Note the async keyword in the signature.

    public async Task ExecuteAsync(RestRequest request) where T : new()
    {
        var client = new RestClient();
        client.BaseUrl = BaseUrl;
        client.Authenticator = new HttpBasicAuthenticator(_accountSid, _secretKey);
        request.AddParameter("AccountSid", _accountSid, ParameterType.UrlSegment);
        IRestResponse response = await client.ExecuteTaskAsync(request);
        return response.Data;
    }
    

提交回复
热议问题