windows 10 apps DownloadOperation not starting(windows 10 应用程序下载操作未启动)
问题描述
我正在尝试在 Windows 10 通用应用程序上使用此代码下载文件:
I'm trying to download a file using this code on a windows 10 universal app:
await downloadOperation.StartAsync().AsTask(token, progressCallback);
它可以在电脑上运行,但在移动设备上有时它不会开始下载,甚至在我重新启动移动设备之前都不会出现异常.是系统错误还是我遗漏了什么?
it's working on pc but on mobile sometimes it's doesn't start downloading and not even giving an exception until I restart the mobile. Is it a bug in the system or I'm missing something?
编辑 1:
任务的状态是等待激活",所以它不会抛出异常.它只是在等待,直到我重新启动手机才开始我一直在尝试使用相同的 url,我在电脑上没有这个问题.只和手机有关.该任务的属性如下:
the task's status is "waiting for activation" so it's not throwing an exception. it's just waiting and not starting until I restart the phone I'm trying always with the same url and I don't have this problem on the pc. It's about the phone only. The task's properties are the following:
推荐答案
我终于找到了问题所在.当我开始下载操作并关闭应用程序而不取消操作时,BackgroundDownloader 会为下一次应用程序启动保留该操作.当下载操作的数量达到最大允许同时操作(我认为 5)时,下一个操作将在等待列表()上,直到前一个操作完成.所以当应用程序这样启动时,我不得不停止所有未完成的操作:
I found the problem finally. when I start a download operation and close the application without cancelling the operation the BackgroundDownloader keeps the operation for the next application start. when the number of download operations reach the maximum allowed simultaneous operations(I think 5) the next operations will be on the waiting list() till the previous operations finish. so I had to stop all the uncompleted operations when the application starts like this:
Task.Run(async () =>
{
var downloads = await BackgroundDownloader.GetCurrentDownloadsAsync();
foreach (var download in downloads)
{
CancellationTokenSource cts = new CancellationTokenSource();
download.AttachAsync().AsTask(cts.Token);
cts.Cancel();
}
var localFolder = ApplicationData.Current.LocalFolder;
var files = await localFolder.GetFilesAsync();
files = files.Where(x => x.Name.EndsWith("_")).ToList();
foreach (StorageFile file in files)
{
await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
});
这篇关于windows 10 应用程序下载操作未启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:windows 10 应用程序下载操作未启动


基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01