eeadev
eeadev

Reputation: 3852

Windows store app 8.1 - Background Task not triggered

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

Upvotes: 1

Views: 633

Answers (2)

iTR
iTR

Reputation: 186

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();

Upvotes: 2

iam.Carrot
iam.Carrot

Reputation: 5286

You are using TimeTrigger Task in response to a Trigger(fire). The minimum time between TimeTrigger Task must be 30 minutes. So you can perform a background task after every 30 minutes. It's similar to the Periodic Trigger in windows 8. So your Updated code line would be:

builder.SetTrigger(new TimeTrigger(30, false));

Upvotes: 0

Related Questions