无法从后台下载操作访问部分数据 [英] Cannot access partial data from a background download operation

查看:59
本文介绍了无法从后台下载操作访问部分数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GetResultStreamAt(int)API在操作完成之前检索并使用后台下载操作的部分结果。正在下载的文件是文本文件。但是,在下载
完成之前,似乎无法访问流。我有一个存储文件,我尝试将数据写入,但只有在下载所有数据后才写入文件。这是进程处理程序中的代码:

 if(operation.Progress.HasResponseChanged)
{
//暂停传输以测试输出部分数据到我的存储文件
file.Operation.Pause();

IInputStream input = operation.GetResultStreamAt(0);
Stream inputStream = input.AsStreamForRead();
Stream outputStream = await myStorageFile.OpenStreamForWriteAsync();
inputStream.CopyTo(outputStream);
outputStream.Flush();
}



当我运行代码时,CopyTo调用永远不会完成。如果我删除Pause(),那么存储文件确实写入正确但只有在下载完成后才能写入。同样,我要做的是将部分下载的数据逐步写入存储
文件。也尝试使用IBuffer,结果相同。看起来代码只有在完全检索后才能从下载操作中访问输入流。我是否正确?

解决方案

本周我会看。

I'm trying to retrieve and use the partial results of a background download operation before the operation completes, using the GetResultStreamAt(int) API. The file being downloaded is text file. However it seems the stream can't be accessed until the download is complete. I have a storage file that I try to write the data to, but the file is only written to once all the data has been downloaded. Here's the code in the progress Handler :

if (operation.Progress.HasResponseChanged)
                {
//pause the transfer to test outputting partial data to my storage file
                    file.Operation.Pause();

IInputStream input = operation.GetResultStreamAt(0); Stream inputStream = input.AsStreamForRead(); Stream outputStream = await myStorageFile.OpenStreamForWriteAsync(); inputStream.CopyTo(outputStream); outputStream.Flush(); }


When I run the code the CopyTo call never completes. If I remove Pause() then the storage file does get written to correctly but only after the download is complete. Again, what I'm trying to do is write partially downloaded data incrementally to the storage file. Also tried using an IBuffer, same result. Looks like the code can only access the input stream from the download operation once its fully retrieved. Am I correct ?

解决方案

I'll look this week.


这篇关于无法从后台下载操作访问部分数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆