Windows 8 Store Apps–Debugging Background Tasks

I’m sure this is written down somewhere but I’ve not come across it so I thought I’d write it down here.

At our UK Windows 8 Camps we talk about the process lifecycle for a Windows 8 Store app and how a developer needs to think about the steps of suspend/resume/terminate for an app.

We also talk about how the Visual Studio 2012 debugger has explicit support for helping with this ( on the Debug Location toolbar ) with its menu;

image

and we also talk about how an application won’t suspend when it’s under the debugger unless you use these buttons.

Finally, we also talk about background tasks and how those work in the system.

What I hadn’t fully appreciated until today was that the debugger also has support for activating your background tasks. You can see in the image above that my application has registered a background task called “Tidy Up Redundant Images”.

In this case, that task is implemented in .NET and, to be a background task, it’s a WinRT component and it’s configured to run as a maintenance trigger every 15 minutes if the user has AC power.

What I hadn’t realised was that the debugger had support for activating that background task so that I don’t have to sit around for 15 minutes waiting for it to kick into life. You probably knew this. I didn’t Smile

So, if I run up my app and let it register its tasks and then click on that little button up there my code breaks at the entry point into my background task straight away;

image

Very cool – I wish I’d noticed this earlier!