简体   繁体   中英

Schedule time logic (TimeTrigger) for specific time of day

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 ?

只需让您的代码每小时运行一次,然后在触发时检查它是否在“夜间”(大概您不希望它做任何事情),如果不执行任何操作。

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.

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