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
Are there classes that support async/await usable for web access in the WP8 BCL?
This is a concern that has been raised during the closed beta of the WP8 SDK, so I can answer that unfortunately, no.
But as you mentioned, it is reasonably easy to make your own wrappers.
For instance:
public static class Extensions
{
public static Task DownloadStringTask(this WebClient webClient, Uri uri)
{
var tcs = new TaskCompletionSource();
webClient.DownloadStringCompleted += (s, e) =>
{
if (e.Error != null)
{
tcs.SetException(e.Error);
}
else
{
tcs.SetResult(e.Result);
}
};
webClient.DownloadStringAsync(uri);
return tcs.Task;
}
}