[英]Internet access in a long-running background task
In my Windows Phone 10 app, I've got a long-running background task, triggered by an RfcommConnectionTrigger. 在Windows Phone 10应用程序中,我有一个由RfcommConnectionTrigger触发的长期运行的后台任务。 This task will run for as long as my bluetooth Rfcomm device is connected. 只要连接了蓝牙Rfcomm设备,该任务就会运行。
Now what I want to achieve is this: 现在我要实现的是:
The problem with #2 is that as soon as I lock the device, all HTTP requests for some reason start failing. #2的问题在于,一旦我锁定了设备,由于某种原因,所有HTTP请求都会开始失败。 I'm just using the System.Net.Http.HttpClient
to do a request, nothing special is going on there. 我只是在使用System.Net.Http.HttpClient
发出请求,那里没有什么特别的事情。 More specifically, the exception is thrown in HttpClient.SendAsync
. 更具体地说,该异常在HttpClient.SendAsync
引发。
How do I get around this limitation? 如何解决此限制?
I found the solution. 我找到了解决方案。 This seems to be a completely undocumented "feature" -- you need to add a SystemConditionType.InternetAvailable
condition to your background task to allow it to use internet when the device is locked. 这似乎是一个完全未记录的“功能”-您需要在后台任务中添加SystemConditionType.InternetAvailable
条件,以使其在锁定设备时可以使用Internet。 I'm hoping that this doesn't mean that when the phone loses internet access, the background task is killed. 我希望这并不意味着当电话无法上网时,后台任务将被杀死。
It also means that the phone now needs to be connected to the internet in order to start the background task, which is still annoying, but I guess I can live with that. 这也意味着电话现在需要连接到互联网才能启动后台任务,这仍然很烦人,但是我想我可以接受。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.