Using async/await with WebClient in Windows Phone 8 (or: TaskCompletionSource saves the day)

When you share code between Windows Phone 8 and Windows 8, you can use async/await to code against asynchronous APIs, which is a nice step in the right direction. However there are Windows Phone APIs that do not support async/await yet. Probably the most annoying to date is the WebClient (which in Windows 8 has been replaced by a better API called HttpClient).

Read the rest of this entry ยป

Print | posted on Sunday, January 27, 2013 4:52 PM

Feedback

# re: Using async/await with WebClient in Windows Phone 8 (or: TaskCompletionSource saves the day)

left by Daniel Plaisted at 1/27/2013 6:57 PM Gravatar
The Microsoft.Bcl.Async NuGet package has DownloadStringTaskAsync extension methods on WebClient, which means you don't have to write your own wrappers (if you don't want to).

You might be able to simplify the MultiRssService example by using Task.WhenAll<T>() to wait for all the operations to be complete.

# re: Using async/await with WebClient in Windows Phone 8 (or: TaskCompletionSource saves the day)

left by Andrew Butler at 1/27/2013 7:09 PM Gravatar
Great post on how to use the TaskCompletionSource. Actually I'm doing something very similar by as Daniel mentioned above, I'm using the Microsoft Bcl Async package but it's good to know how to use it elsewhere.

# re: Using async/await with WebClient in Windows Phone 8 (or: TaskCompletionSource saves the day)

left by Laurent Kempé at 1/28/2013 9:52 AM Gravatar
Hi Laurent

Thanks for your article which reminded that I also wrote about it "Extending existing .NET API to support asynchronous operations" - http://www.laurentkempe.com/post/Extending-existing-NET-API-to-support-asynchronous-operations.aspx

Cheers
Laurent

# re: Using async/await with WebClient in Windows Phone 8 (or: TaskCompletionSource saves the day)

left by Laurent at 1/28/2013 10:43 AM Gravatar
Hey Laurent yourself ;)

Well done. I guess we all have the same problems to solve around the same time huh?

Cheers!
Laurent
Comments have been closed on this topic.