简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM