How do I keep a Timer alive in .net Maui when the app is backgrounded?

496 views Asked by At

I'm hoping there is a cross-platform solution to keep a timer going when the app is backgrounded.

I'm trying to make a walking app for Android and iOS and the timer has to keep track of how long the user has walked and show that to the user anytime they bring the app out of the background.

I have Shiny 3.0, but according to Allan Ritchie, Shiny won't do that. Can anyone help? I have this code in the ViewModel.

 private void RunTimer()
 {
     _dispatcher.StartTimer(TimeSpan.FromMilliseconds(100), () =>
     {
         _dispatcher.Dispatch(() =>
         {
             App.TotalRunningTime = DateTime.Now - App.CurrentWalkStartingDateTime - App.TotalPausedTime;

             var hours = App.TotalRunningTime.Hours;
             var minutes = App.TotalRunningTime.Minutes;
             var seconds = App.TotalRunningTime.Seconds;

             TimerText = String.Format("{0:00} : {1:00} : {2:00}", hours, minutes, seconds);

             //     StepsCount = DependencyService.Get<IStepCounter>().Steps;
         });

         return TimerRunning;
     });
0

There are 0 answers