Sushil_Arora
Sushil_Arora

Reputation: 58

[UWP]Running Background Tasks for more than 30sec

In UWP, I have a timer task which runs every 15 minutes. The Background Tasks for timer trigger is allowed to run only for 30 seconds. But, in some cases I need the background task to run for more than 30 seconds. Also, this is required when the app is in suspended state. Any suggestions how this can be achieved?

Upvotes: 1

Views: 1800

Answers (1)

Scavenger
Scavenger

Reputation: 205

For long-running background tasks, there are three triggers: MaintenanceTrigger, ApplicationTrigger and DeviceUseTrigger. You may use MaintenanceTrigger if every 15 min is required. Its function is same as timer trigger. But

Background tasks that use a maintenance trigger run only when the system is connected to AC power.

So like @kennyzx said, it's better to make it finished within 30s as background tasks are needed to be lightweight. It has a lot of additional resource constraints .Windows will terminate background task when memory or battery stays in a low level. For example, we shouldn't handle download with background task because it is long time operation, we should use BackgroundTransfer in that situation . if we need to deal with some simple operations like pushing a notification or updating a tile, background task is perfect . Keeping background execution to a minimum ensures the best user experience with foreground apps and battery life.

Upvotes: 3

Related Questions