c# - RandomAccessStream.CopyAndCloseAsync 需要互联网吗?
问题描述
我在这里有一个 UWP 应用程序。在这个 UWP 应用程序中,我正在下载文件。有人注意到,在另一个国家,他们的防火墙阻止了下载,UWP 应用程序冻结了。在他们的机器上调试时,我注意到在await RandomAccessStream.CopyAndCloseAsync(inputStream, outputStream);
UWP 应用程序冻结之后,下一步永远不会在调试模式下发生。你不能再在 UWP 应用程序中做任何事情了。
我之前可以通过断开互联网在我的机器上重新创建它await RandomAccessStream.CopyAndCloseAsync(inputStream, outputStream);
。当连接回 Internet 时,会在调试模式下进行下一步,并且 UWP 应用程序可以像以前一样正常工作。
现在我想知道......是什么导致了这个问题?我需要 Internet 连接await RandomAccessStream.CopyAndCloseAsync(inputStream, outputStream);
吗?我该如何解决它,让它忽略await RandomAccessStream.CopyAndCloseAsync(inputStream, outputStream);
这些步骤?
async public Task DownloadFile(Uri url, string filename)
{
Windows.Web.Http.HttpResponseMessage response = await client.GetAsync(url, Windows.Web.Http.HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsInputStreamAsync();
IInputStream inputStream = await response.Content.ReadAsInputStreamAsync();
StorageFolder folder = await App.GetDocumentFolder();
StorageFile file = await folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
IOutputStream outputStream = await file.OpenAsync(FileAccessMode.ReadWrite);
await RandomAccessStream.CopyAndCloseAsync(inputStream, outputStream);
}
解决方案
推荐阅读
- python - Python 与 C 中的递归函数
- vb.net - OleDBCommands:执行两个命令并检查
- python - Pandas 双引号列名
- python - Flash 消息未显示在页面上
- javascript - 只选择一张卡reactjs
- firebase - Firestore 规则不接受来自 Stripe (stripeRole) 的自定义声明
- lua - 是否可以在 Lua 中将参数绑定到作为参数传递给另一个函数的回调函数?(JavaScript 的“绑定”等价物)
- c# - 表单图标不会显示在 WinForms 中
- github - 如何突出显示 github 自述文件中的表格行?
- flutter - 有没有办法使 scrollPhysics 与 ListView for Column 小部件中的相同?