首页 > 解决方案 > 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);
    }

标签: c#uwpstreaminputstreamoutputstream

解决方案


推荐阅读