Downloading and saving a file Async in Windows Phone 8
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I download and save a file to IsolatedStorage asynchronously? I used WebClient first for the purpose, but I couldn't await till completion so I found some useful code here . However, this is also not in complete format. I found the function: public static Task DownloadFile(Uri url) { var tcs = new TaskCompletionSource (); var wc = new WebClient(); wc.OpenReadCompleted += (s, e) => { if (e.Error != null) tcs.TrySetException(e.Error); else if (e.Cancelled) tcs.TrySetCanceled(); else tcs.TrySetResult(e.Result); }; wc.OpenReadAsync(url);