Registering BackgroundTask is pretty well explained here on MSDN .
Here is a simple example given in TimeTrigger that shows Toast steps (applicable to both RunTime and Silverlight applications):
- 1. BackgroungTask should be a component of Windows Runtime (regardless of whether your application is Runtime or Silverlight). To add a new one, right-click on your solution in the Solution Explorer window in VS, select
Add , then
New project and select the Windows Runtime component.

- 2. Add the link to your main project.

- 3. Indicate
Declarations in the Package.appxmanifest file - you need to add the Backgorund task, mark the timer and specify the entry point for the task. The entry point will be
Namespace.yourTaskClass (which implements
IBackgroundTask ) - an added component of Windows Runtime.

- 4. What might your BackgroundTask look like? - let's say we want to send a toast from it (of course, it can be a lot of things):
namespace myTask
- 5. Finally, let
will register our BackgroundTask in the main project:
private async void Button_Click(object sender, RoutedEventArgs e) { // Windows Phone app must call this to use trigger types (see MSDN) await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder { Name = "First Task", TaskEntryPoint = "myTask.FirstTask" }; taskBuilder.SetTrigger(new TimeTrigger(15, true)); BackgroundTaskRegistration myFirstTask = taskBuilder.Register(); }
Compile, run and run. As you can see, the task should start after 15 minutes (this time may vary depending on how the OS assigns the task at certain time intervals, so it works between 15-30 minutes). But how to debug a task faster?
There is an easy way - go to the "Debugging" toolbar and you will see the drop-down events of the life cycle, select your task from it, and it will open (sometimes open / close) to update it.

Here you can download my sample code - the WP8.1 Silverlight application.
source share