重新连接到多个后台传输:传输按顺序而不是并行恢复 [英] Reattaching to multiple background transfers : transfers resumed sequentially instead of in parallel

查看:85
本文介绍了重新连接到多个后台传输:传输按顺序而不是并行恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Metro应用,可以使用BackgroundTransfers API创建几个后台下载。在我的应用程序启动代码中,我重新连接到待处理的bg传输操作。该应用程序成功重新附加到bg下载,这反映在我的进度
栏中显示部分完成,但是,只有一个转移在应用程序启动时恢复,并且直到第一个完成后下一个恢复,所以on。

I have a Metro app that creates a couple of background downloads using the BackgroundTransfers API. In my code at app launch I reattach to pending bg transfer operations. The app successfully reattaches to the bg downloads, as reflected in my progress bars which show partial completion, however, only one transfer resumes at app start, and it's not until the first one completes that the next one resumes, and so on.

我检查了BackgroundTransfer示例并发现它具有相同的行为,即使代码中有特定注释可以避免此行为。以下是示例代码的摘录 :

I examined the BackgroundTransfer sample and found it has the same behavior even though there are specific comments in the code for avoiding this behavior. Here's an excerpt of the sample's code :

if (downloads.Count > 0) { List<Task> tasks = new List<Task>(); foreach (DownloadOperation download in downloads) { Log(String.Format("Discovered background download: {0}, Status: {1}", download.Guid, download.Progress.Status)); // Attach progress and completion handlers. tasks.Add(HandleDownloadAsync(download, false)); } // Don't await HandleDownloadAsync() in the foreach loop since we would attach to the second // download only when the first one completed; attach to the third download when the second one // completes etc. We want to attach to all downloads immediately. // If there are actions that need to be taken once downloads complete, await tasks here, outside // the loop. await Task.WhenAll(tasks); }

因此示例应用检索并将待处理的bg转移存储到任务集合中以避免必须顺序等待每个任务,这是为了避免顺序下载行为。这就是Task.WhenAll(tasks)调用的内容。但是,如果您
:运行示例,请在某些服务器上指定要下载的第一个文件的uri并点击"开始下载",然后对第二个文件执行相同操作,然后转到任务管理器,等待应用程序被暂停,杀死应用程序,然后转到开始菜单并重新启动示例应用程序
,让它重新连接到您创建的2个正在进行的传输,您看到确实找到了两个后台下载,但只有一个它们立即恢复,第二次转移仅在第一次完成后开始。我相信这个
正是代码试图避免的。

So the sample app retrieves and stores pending bg transfers into a task collection to avoid having to await each task sequentially, which is to avoid having a sequential download behavior. That's what the Task.WhenAll(tasks) call is for. However, if you : run the sample, specify the uri of a first file to download on some server and hit 'start download', then do the same for a second file, then go to the Task Manager, wait for the app to get suspended, kill the app, then go to the start menu and relaunch the sample app to let it reattach to the 2 ongoing transfers your created, you see that both background downloads are indeed found, but only one of them resumes right away, with the second transfer only starting after the first one completes. I believe this is exactly what the code is trying to avoid.

我错过了什么吗?

Am i missing something ?

推荐答案

今天我会看一下。


这篇关于重新连接到多个后台传输:传输按顺序而不是并行恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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