Hello
I just start learing Xamarin for a few week,now i want a Timer that Works Non-Stop when a i go to another pages! i use MVVM for that, but when i go to another pages and come back it's start from zero again. how can i do that in xamarin?
` Timer tmr = new Timer();
tmr.Interval = 1000;
tmr.Elapsed += delegate
{
Sec++;
};
tmr.Start();
}
private int sec=1;
public int Sec
{
get { return sec; }
set
{
sec = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Sec)));
}
}
`
and in Xaml i use Bindindcontext,it works fine
- even i use this type of code in CS code behind page thats work fine but every time came to this page its start from zero:
Timer tmr = new Timer();
tmr.Interval = 1000;
tmr.Elapsed += delegate {
Sec++;
Device.BeginInvokeOnMainThread(() =>
{
txtsec.Text = Sec.ToString();
});
};
tmr.Start();