Andrei
Andrei

Reputation: 44550

Run frequent background task on Windows Phone 8.1

Windows Phone platform offers BackgroundTasks infrastructure. I can register my task like that:

builder.TaskEntryPoint = TaskName;
var trigger = new TimeTrigger(15, false);

builder.SetTrigger(trigger);
builder.Register();

The problem is, that TimeTrigger min interval is ~15 minutes, which is pretty large for my application. I need to have task which runs every 1-2 minutes in the background. Is it possible on Windows Phone?

Upvotes: 3

Views: 2690

Answers (2)

Romasz
Romasz

Reputation: 29792

AFAIK with the official API - it's not possible to run TimeTrigger so often. Note that on WIndows Phone, the interval is even larger (MSDN):

Windows has a built-in timer that runs background tasks in 15-minute intervals. Note that on Windows Phone, the interval is 30 minutes.

I doubt it will be possible, due to battery consuption/restrictions. Maybe you can leave your app in the foreground and disable lockscreen (by using DisplayRequest).

Also you may try to run a timer along with obtaining deferal in your BackgroundTask. I've not tried that, for sure there will be many problems (CPU limit, memory and other restrictions), I'm not sure if that is not against certification requirements and of course it doesn't guarantee that your BackgroundTask wouldn't be terminated by OS.

Upvotes: 2

meneses.pt
meneses.pt

Reputation: 2616

It is not possible to have BackgroundTasks that run on a minute interval basis. As you said already the minimum interval is 15 minute.

This is an OS limitation to prevent developers to build battery draining applications.

You always have some workarounds, like having a PushNotificationTrigger, and manage to send a push notification to your device every minute. (I guess some people manage to do so with the ScheduledToastNotification), but i wouldn't recomend it.

Upvotes: 3

Related Questions