I have DispatcherTimer in my app which counts how long my app has been active and I’d like to call DispatcherTimer.Stop() when user navigates to other app (so it doesn’t count anymore). And then resume counting when user goes back to my app.
How to do that?
In the Suspending event of the Application class, execute the method DispatcherTimer.Stop().
In the Resuming event of the Application class, resume the DispatcherTimer.
The Suspending event of the Application class will execute when the user switches apps or just navigates away from your application. The Resuming event will execute when the user focuses your app and brings it to the foreground.
See:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.suspending.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.resuming.aspx