Question

I am working on windows phone application where I am implementing a background task timertrigger which should trigger based on the options below,

  1. Hourly
  2. During the day ( 9am - 5pm)
  3. During the night ( 5pm - 9am)

The RegisterBackgroundTask() function usually requires a time to be specified when the trigger should kick in. What is the best way to do this for the options above.

I got it for the 1st option where I set it as 60 minutes. During the day and during the night has left me a little confused.

What would be the best practice to implement this ?

Was it helpful?

Solution 2

Found a way to do this.

For During the day, I make the background task run every 15 minutes and it check if the current time is between 9am and 5pm, if yes, it syncs else it exits and waits.

For At Night, I make the background task run every 15 minutes and it check if the current time is between 5pm and 9am, if yes, it syncs else it exits and waits.

Once the sync is done, i store the last synced time in a storage variable and every minutes even the last sync time is checked to see if its greater than 24 years for a subsequent sync.

OTHER TIPS

Just have your code run hourly and then when triggered it checks if it is "during the night" (where presumably you don't want it to do anything) and if so not perform any action.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top