Call a function every ten seconds while App is sleeping

SzbestaSzbesta Member ✭✭✭

Hey Guys!
Been sitting on this problem the whole day and i can't seem to figure out the issue. I'm trying to check my DB every 10 seconds to send a Notification when some data is missing. I've been trying to achieve this by using the OnSleep() Method in my App.xaml.cs. Currently it looks something like this:

Device.StartTime(TimeSpan.FromSeconds(10), callback: () => 
{
  var Notificator = DependencyService.Get<IToastNotificator>();
  var Options = new NotificationOptions
                {
                    Title = "Test",
                    Description = "This is a 10 second test",
                    AndroidOptions = new AndroidOptions
                    {
                        ForceOpenAppOnNotificationTap = true
                    }
                };
                Notificator.Notify(Options);
return true;
}

Thing is this still fires a Notification even when the app is in the foreground(being used) after it has been backgrounded. I figured that if I do it this way as soon as the App gets put to sleep this method continues to execute although the App isnt in the "sleep" state anymore. So my question now is how do I achieve that this is called every 10 seconds ONLY when the App is sleeping ? I'd rather you point me in the right direction than give me a full blob of code :)

Thanks in advance!
Best regards,
Szbesta :)

Answers

Sign In or Register to comment.