I have a background task which executes a http request, but only works a small number of times. The error returned is: "The server name or address could not be resolved". The url is correct and works fine if I execute it from main app.
The code is a simple http request with a "HttpClient":
public async void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
try
{
using (var client = new HttpClient())
{
var c = await client.GetStringAsync("http://www.google.com");
}
}
catch (Exception e)
{
}
finally
{
_deferral.Complete();
}
}
As I've said, the same url Works sometimes and sometimes not, and yes, I'm checking internet connection before each request. Any ideas please?
EDITED: Here is my phone info:
And here is the repo with a test app demonstrating the issue: https://github.com/CabuxaMapache/BackgroundTask.Test
EDITED 2: I've tested the app in a Lumia 640 with the same results, over 100 executions and only 10 of them OK. Here is the L640 info:
Thanks in advance
So, finally, the answer is here: https://docs.microsoft.com/en-us/uwp/api/Windows.ApplicationModel.Background.BackgroundTaskBuilder#properties_, thanks Dave Smits!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments