后台文件传输问题
我在 WP7 中使用后台文件传输时遇到此问题。当我的应用程序运行时,它工作得很好,但是一旦我单击 Windows 按钮,它就会停止(并在我再次激活应用程序时恢复。)后台文件传输的目的不是在后台运行,即使您的应用程序已停用?它是否必须位于一个单独的类中(某种后台代理类,与主项目分开?)当我执行此处教程中所说的所有内容时,真的很令人沮丧: http://msdn.microsoft.com/en-us/library/hh202959(v=vs.92).aspx。
我需要做一些“特殊”的事情来确保它在后台运行,或者一些方法,也许是我自己创建的方法(以获取网址等),在停用时无法访问?我可以在停用时不添加到队列吗?
非常感谢您的时间:)
编辑:一点调试告诉我队列中的文件实际上正在下载。它已完成,但在我重新激活应用程序之前它不会获取下一个。这样做时我可以不使用自己的方法、变量等吗?也许我有一个内部队列,可以容纳 20 个项目。当下载队列为零时,我该如何填充下载队列(最多 5 个)?
EDIT2:在 Microsoft 的示例中,他们说您可以稍后添加到队列中:
// Check to see if the maximum number of requests per app has been exceeded.
if (BackgroundTransferService.Requests.Count() >= 5)
{
// Note: Instead of showing a message to the user, you could store the
// requested file URI in isolated storage and add it to the queue later.
MessageBox.Show("The maximum number of background file transfer requests for this application has been exceeded. ");
return;
}
但它没有说明我们是否可以在后台执行此操作。既然是关于后台文件传输,他们应该提到它,否则我们应该假设它可以在后台完成,但事实似乎并非如此。但我们无法知道这一点。谁能100%确认这一点?
I have this problem when using the Background File Transfer in WP7. It works perfectly when my application is running, but as soon as I click the Windows button, it stops(and resumes when I activate the application again.) Isn´t the purpose of Background File Transfer to run in the background, even when your application is deactivated? Does it have to be in a separate class(some sort of background agent class, separate from the main project?) Really frustrating, when I am doing all that the tutorial here says: http://msdn.microsoft.com/en-us/library/hh202959(v=vs.92).aspx.
Are there some "special" things I need to do to make sure it runs in the background, or some methods, maybe the ones I created by myself(to get the url etc.), that can not be accessed while deactivated? Can I not add to the queue while deactivated, maybe?
Thanks a lot for your time:)
EDIT: A little debugging tells me that the file in the queue is actually downloading. It gets finished, but it doesn´t fetch the next one until I reactivate the app. Can I not use my own methods, variables etc when doing this? Maybe I have an internal queue for, say, 20 items. How can I then populate the download queue(max 5) when this gets to zero?
EDIT2: In the sample from Microsoft, they say that you can add to the queue at a later time:
// Check to see if the maximum number of requests per app has been exceeded.
if (BackgroundTransferService.Requests.Count() >= 5)
{
// Note: Instead of showing a message to the user, you could store the
// requested file URI in isolated storage and add it to the queue later.
MessageBox.Show("The maximum number of background file transfer requests for this application has been exceeded. ");
return;
}
But it does not say if we can do this while in background or not. Since it is about background file transferring, they should have mentioned it, otherwise we should assume it can be done in the background, which seems not to be the case. But we can´t know that. Anyone who can confirm this 100%?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也研究过这个问题,并且不可能(根据我的研究)在最大值之后填充队列。 5 个排队下载已完成。我考虑过使用后台代理,但后台代理无法使用BackgroundTransferRequest.Add,这意味着排队更多下载的唯一方法是当您的应用程序运行时(请参阅Windows Phone 后台代理不支持的 API)。
我唯一能想到的是使用后台代理发送 toast 通知,让用户知道下载已完成,并且他们应该启动应用程序来排队接下来的五个下载。这不太理想。
I have looked into this as well and it isn't possible (based on my research) to populate the queue after the max. 5 queued downloads have finished. I thought about using a background agent but BackgroundTransferRequest.Add is unavailable from background agents meaning the only way to queue more downloads is when your app is running (see Unsupported APIs for Background Agents for Windows Phone).
The only thing I can think of is using a background agent to send a toast notification letting the user know that the downloads have finished and that they should start the app to queue the next five downloads. This is less than ideal.