Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Device.StartTimer does not invoke callback method.

$
0
0

Hey Guys,

I am developing a cross platform poker app using xamarin and PCL. I'm using Profile78 for PCL. I want to write down some logic in PCL so that it can fetch data from server after every 5 seconds and show it on device screen. I'm trying to achieve this by using Device.Timer class. The challenge I'm facing is, when the timer lapses after 5 seconds it doesn't invoke the callback method. Here is the code snippet.

int KeepAliveTimer = 5000;
Device.StartTimer(new TimeSpan(0, 0, 0, 0, KeepAliveTimer), () =>
{
TimeSpan differ = receiveKeepAliveDate.Subtract(sendKeepAliveDate);
KeepAliveTimer = Convert.ToInt32(differ.TotalMilliseconds) + 5000;
if (KeepAliveTimer < 5000)
{
KeepAliveTimer = 5000;
}
OnKeepAliveTimer();
return true;
});

I also tried with rather a simpler version but that also seems not working.

Device.StartTimer(new TimeSpan(0, 0, 0, 5, 0), TimerCallBack);

private bool TimerCallBack()
{
OnKeepAliveTimer();
return true;
}

Could you guys please help me out in getting why the callback method is not invoking. I tried every possible solution I found on Google but nothing seems working here.


Viewing all articles
Browse latest Browse all 77050

Trending Articles