Client.GetAsync appears to fail for me when running in a background task in my Windows 8 Metro app.
I tried using both a TimeTrigger and a MaintenanceTrigger. It ap
I had a similar problem to you before, and the way I solved it was to have another deferral in the async task. I think the idea is that, whenever you have an async task, you need a deferral. (I'm not sure if it's best practice, but hey, it works)
Code:
public void Run(IBackgroundTaskInstance taskInstance)
{
updateAllTiles(taskInstance);
}
public async void updateAllTiles(IBackgroundTaskInstance taskInstance)
{
// Need to use a deferral to run async tasks in the background task
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
dosomething(taskInstance);
deferral.Complete();
}
private async void dosomething(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
HttpClient client = new HttpClient();
HttpResponseMessage resp = await client.GetAsync(new Uri(url));
updateTile(resp);
deferral.Complete();
}