Kirill Kirill - 8 days ago 5
C# Question

Timer doesn't contain in System.Threading at Xamarin.Forms

I used

System.Threading.Timer
in
Xamarin.Android
.

How I can use the same class in
Xamarin.Forms
?
(I want to transfer my project from Xamarin.Android in Xamarin.Forms)

public static System.Threading.Timer timer;
if (timer == null)
{
System.Threading.TimerCallback tcb = MyMethod;
timer = new System.Threading.Timer(tcb, null, 700, System.Threading.Timeout.Infinite);
}
else
{
timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
timer.Change(700, System.Threading.Timeout.Infinite);
}

Answer

System.Threading.Timer is not available in PCL code. You can use the Xamarin.Forms.Device.StartTimer method instead as explained here: http://developer.xamarin.com/api/member/Xamarin.Forms.Device.StartTimer/