Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Timer missing from Xamarin PCL

I am building a Xamarin cross platform app targeting IOS Android and Windows Phone 8.1 using .Net 4.5.1. When I try to reference System.Timers in the PCL project, it is not there. How do I fix this?

like image 394
Sepehr Sobhani Avatar asked Jun 29 '15 03:06

Sepehr Sobhani


1 Answers

You can use : Device.StartTimer

Syntax :

public static void StartTimer (TimeSpan interval, Func<bool> callback)

Examples : increment number every 1 seconds for 1 minutes

int number = 0;
Device.StartTimer(TimeSpan.FromSeconds(1),() => {
    number++;
    if(number <= 60) 
    {
        return true; //continue
    }
    return false ; //not continue

});

Examples : wait for 5 seconds to run function one time

Device.StartTimer(TimeSpan.FromSeconds(5),() => {
    DoSomething();
    return false ; //not continue
});
like image 91
jojobarcream Avatar answered Sep 23 '22 13:09

jojobarcream