窗10应用DownloadOperation无法启动 [英] windows 10 apps DownloadOperation not starting

查看:210
本文介绍了窗10应用DownloadOperation无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用在Windows 10通用的应用程序的代码来下载一个文件:

 等待downloadOperation.StartAsync( ).AsTask(令牌,progressCallback); 



它的工作在PC上,但是,有时移动它没有开始下载,甚至不给一个异常,直到我重新启动手机。
是它在系统中的错误还是我失去了一些东西。



修改1:



该任务的状态为等待激活,所以它不是抛出一个异常。
,它只是在等待,而不是开始,直到我重新启动手机
我与相同的URL总是想,我没有在PC这个问题。这是关于只手机。
任务的属性如下:


< DIV CLASS =h2_lin>解决方案

我终于发现了问题。
当我开始下载操作,没有取消BackgroundDownloader保持操作的下一个应用程序启动操作关闭应用程序。
当下载操作的次数达到允许的同时操作(我认为5)接下来的操作将在轮候名单(),直到前面的操作完成的最大。
,所以我不得不停止所有未完成的操作应用程序启动时是这样的:

  Task.Run(异步( )=> 
{
变种下载=等待BackgroundDownloader.GetCurrentDownloadsAsync();
的foreach(在下载变种下载)
{
CancellationTokenSource CTS =新CancellationTokenSource() ;
download.AttachAsync()AsTask(cts.Token);
cts.Cancel();
}
VAR localFolder = ApplicationData.Current.LocalFolder;
var中的文件=等待localFolder.GetFilesAsync();
=文件fil​​es.Where(X => x.Name.EndsWith(_))了ToList();
的foreach(在文件中StorageFile文件)
{
等待file.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
});


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?

Edit 1:

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:

解决方案

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);
            }
        });

这篇关于窗10应用DownloadOperation无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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