Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a timer in Xamarin?

So I need to have a timer to count down from 60 seconds. I am new to Xamarin and have no idea what it accepts. It will be used in Android.

Any suggestions on how to start?

Can you use System.Timers.Timer?

like image 725
who's.asking Avatar asked Dec 07 '22 16:12

who's.asking


1 Answers

You can use the System.Threading.Timer class, which is documented in the Xamarin docs: https://developer.xamarin.com/api/type/System.Threading.Timer/

Alternatively, for Xamarin.Forms, you have access to a cross-platform Timer via the Device class:

Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
    // called every 1 second
    // do stuff here

    return true; // return true to repeat counting, false to stop timer
});
like image 113
Sigge Avatar answered Dec 20 '22 20:12

Sigge