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 appears that there is no exception. When debugging it, it just exits at that line (if I keep pressing step over), even though there is way more to execute as well as a try-catch around it.
This leads me to believe that Windows is cancelling my task. So I listened to the cancelled event with no luck.
I have declared Internet access as a capability, and the task has been properly registered. Furthermore, my app has full lock screen access.
What am I doing wrong?
Here’s the code I use to register the background task currently.
if (await ObtainLockScreenAccess())
{
const string name = "Task";
var updaterTasks = BackgroundTaskRegistration.AllTasks.Where(t => t.Value.Name == name);
if (!updaterTasks.Any())
{
var builder = new BackgroundTaskBuilder();
builder.Name = name;
builder.TaskEntryPoint = "Stackstabilizer.BackgroundTasks.UpdateBackgroundTask";
var trigger = new MaintenanceTrigger(15, false);
var condition = new SystemCondition(SystemConditionType.InternetAvailable);
builder.AddCondition(condition);
builder.SetTrigger(trigger);
var task = builder.Register();
Debug.WriteLine("Task has been registered");
}
}
Edit Here’s the background task signature:
namespace Stackstabilizer.BackgroundTasks
{
// You must use a sealed class, and make sure the output is a WINMD.
public sealed class UpdateBackgroundTask : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
try { ... } finally { deferral.Complete(); }
}
}
}
And here’s some details on my declarations.

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: