ApplicationIdleDetectionMode and DispatcherTimer
I'm currently working on a problem which i'm not able to solve...
I have developed a WP7 app which sends periodical location updates to a service. Therefore I'm using a DispatcherTimer which works great. Now I also want to do this when the screen is locked. So I set ApplicationIdleDetectionMode to "Disabled" 开发者_StackOverflow社区in App() just after InitializePhoneApplication().
Now I have a very strange behavior because the timer which is running as the screen gets locked seems to finish but I cannot start it again. timer.Start() gets called but the Tick-Event does not get called. When I unlock the screen at my device it is working again...
Anyone got an idea how to solve this? Or maybe any other advice how I can achieve such a behavior?
Greetings Dominik
I’m surprised that the framework itself would stop an active timer when the application is locked when ApplicationIdleDetection
is disabled although it's a distinct possibility. In RunKeeper we don’t use a DispatcherTimer
to do that anyway, we keep track of the user’s time on an activity by using Observable.Timer
.
One thing I was going to suggest anyway was that sending position data every time interval might not be the most efficient anyway. If you set a movement threshold on the location service then you will only get a position when the user’s position has changed by that amount, you could then send the position data every time the location has changed. To preserve battery power while the device is locked, you could store the positions, and then send them when the application is reactivated.
精彩评论