none
请教win8.1下载进度问题,通过HttpClient请求服务器资源后,利用流写入本地文件,此过程中有没有可用的回调函数来通知当前下载多少? RRS feed

  • 问题

  •  HttpResponseMessage response = await this.RequestServerOption(serverConfig.ReportServer.serverUrl, WS_CODE_REQ_REPORTING_ITEM, requestDownLoadJson);
                   
                     StorageFolder LocalstorageFolder = KnownFolders.PicturesLibrary;
                     StorageFolder createNewFolder = await LocalstorageFolder.CreateFolderAsync(itemId, CreationCollisionOption.ReplaceExisting);
                     StorageFile createFile = await createNewFolder.CreateFileAsync(itemId + ".zip", CreationCollisionOption.ReplaceExisting);
                     //读取文件流并写入本地
                     using (Stream responseStream = (await response.Content.ReadAsInputStreamAsync()).AsStreamForRead())
                     {
                         byte[] bt=BaseHelper.StreamToBytes(responseStream);
                         using (StorageStreamTransaction transaction = await createFile.OpenTransactedWriteAsync())
                         {
                             using (DataWriter dataWriter = new DataWriter(transaction.Stream))
                             {
                                 dataWriter.WriteBytes(bt);
                                 transaction.Stream.Size = await dataWriter.StoreAsync();
                                 await transaction.CommitAsync();
                             }
    
                         }
                   
                     }

    上面是代码,就是利用HttpClient请求服务器资源,然后通过HttpResponseMessage接收,最后把流写入到本地的过程,这个过程中我怎样能获取到请求的进度呢?想做一个进度在页面上显示具体请求了多少?望大神解答,在线等,,,感谢!
    2014年7月7日 6:11

答案