× ABOUT DOWNLOADS PROJECTS WORK
    cyberpunk.sh
Profile photo

PREMCHAND CHAKKUNGAL

SENIOR SOFTWARE ENGINEER

    AWAITABLE EXECUTE FOR RESTSHARP FOR WINDOWS PHONE 8

RestSharp is a powerful tool for communicating with server for POST operations. But it lacks an awaitable process. The following function will help you to execute the request as awaitable.


public class RestSharpExtensions
{
public Task ExecuteAwait(RestClient client, RestRequest request)
{
TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
client.ExecuteAsync(request, (response, asyncHandle) =>
{
if (response.ResponseStatus == ResponseStatus.Error)
{
taskCompletionSource.SetException(response.ErrorException);
}
else
{
taskCompletionSource.SetResult(response);
}
});
return taskCompletionSource.Task;
}
}