Run a background task every X times

I would like to start a service that after a while on all platforms checked for a popping notification or not. Is there any nuget to connect all platforms or some examples?

+3


source to share


2 answers


You can use the method Device.StartTimer(TimeSpan minutes)

to start a background task that will repeat itself after a specified amount of time. Here's some sample code:

var minutes = TimeSpan.FromMinutes (3); 

Device.StartTimer (minutes, () => {

    // call your method to check for notifications here

    // Returning true means you want to repeat this timer
    return true;
});

      



This is included with Xamarin Forms, so you don't need platform specific logic.

http://iosapi.xamarin.com/index.aspx?link=M%3AXamarin.Forms.Device.StartTimer(System.TimeSpan%2CSystem.Func%7BSystem.Boolean%7D)

+8


source


I think the best you can do is this:

Unfortunately, the way the two platforms have evolved to handle background code is completely different. Thus, we cannot abstract the background function into the Xamarin.Forms library. Instead, we will continue to rely on native APIs to complete our common background task.



More information on this topic can be found here: https://robgibbens.com/backgrounding-with-xamarin-forms/

+1


source







All Articles