I am very new to Windows Store App and I am trying to use a background task.
I register it on a button click event this way: var builder = new BackgroundTaskBuilder();
builder.Name = "bikePositionUpdate";
builder.TaskEntryPoint = "BackgroundTaskGps.BikeGPSPositionUpdateBackgroundTask";
builder.SetTrigger(new TimeTrigger(15, false)); //
BackgroundTaskRegistration taskRegistration = builder.Register();
So it is supposed to be launched within 15'.
Here is my task:
namespace BackgroundTaskGps
{
public sealed class BikeGPSPositionUpdateBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("run run run");
}
}
}
and here my manifest
...
<Extensions>
<Extension Category="windows.backgroundTasks" EntryPoint="BackgroundTaskGps.BikeGPSPositionUpdateBackgroundTask">
<BackgroundTasks>
<Task Type="timer" />
</BackgroundTasks>
</Extension>
</Extensions>
...
But run method is never hit.
Please what could be my problem?
PS: I am testing my app on my local machine (the same development PC).
Please consider that I am not talking about Windows Phone App but Windows App
For Windows Phone You must need to call this
await BackgroundExecutionManager.RequestAccessAsync();
So the complete code is
await BackgroundExecutionManager.RequestAccessAsync();
builder.Name = "bikePositionUpdate";
builder.TaskEntryPoint = "BackgroundTaskGps.BikeGPSPositionUpdateBackgroundTask";
builder.SetTrigger(new TimeTrigger(15, false)); //For Windows Phone 8.1 minimum is 15 minutes
BackgroundTaskRegistration taskRegistration = builder.Register();