Async await in Windows Phone web access APIs

前端 未结 5 1062
闹比i
闹比i 2020-12-29 17:57

Is there support for the async/await pattern in WP8?

I need to get XML from a web-based API and it looks like that WebClient or WebRequest

5条回答
  •  一向
    一向 (楼主)
    2020-12-29 18:01

    I had the same issue and I found this and helped me

    private async Task ExecuteAsync(RestRequest request)
        {
            var tcs = new TaskCompletionSource();
            _client.ExecuteAsync(request, resp =>
            {
                var value = JsonConvert.DeserializeObject(resp.Content);
                if (value.ErrorCode > 0)
                {
                    var ex = new ToodledoException(value.ErrorCode, value.ErrorDesc);
                    tcs.SetException(ex);
                }
                else
                    tcs.SetResult(value);
            });
            return await tcs.Task;
        }
    

    http://www.developer.nokia.com/Community/Wiki/Asynchronous_Programming_For_Windows_Phone_8 also I found this extension helpful http://nuget.org/packages/WP8AsyncWebClient/

提交回复
热议问题