public Windows.Foundation.IAsyncAction DownloadAsync() { _isBusy = true; return(AsyncInfo.Run(async(ct) => { ContentDownloadCompletedArgs args = new ContentDownloadCompletedArgs(_contentUri); HttpClient client = new HttpClient(); HttpResponseMessage resp = await client.GetAsync(args.ContentUri); if (resp.IsSuccessStatusCode) { args.SetData(await resp.Content.ReadAsBufferAsync(), resp.StatusCode); if (this.Completed != null) { this.Completed(this, args); } } else { args.SetData(null, resp.StatusCode); if (this.Error != null) { this.Error(this, new ContentDownloadErrorArgs(resp.StatusCode)); } } _isBusy = false; })); }
public Windows.Foundation.IAsyncAction DownloadAsync() { return AsyncInfo.Run(async (ct) => { ContentDownloadCompletedArgs args = new ContentDownloadCompletedArgs(_contentUri); if (args.Content == null) { HttpClient client = new HttpClient(); HttpResponseMessage resp = await client.GetAsync(args.ContentUri); if (resp.IsSuccessStatusCode) { args.SetData(await resp.Content.ReadAsBufferAsync(), resp.StatusCode); if (this.Completed != null) this.Completed(this, args); } else { args.SetData(null, resp.StatusCode); if (this.Error != null) this.Error(this, new ContentDownloadErrorArgs(resp.StatusCode)); } } else { if (this.Completed != null) this.Completed(this, args); } }); }