While my System.Timers.Timer(); code is running, when I am navigating to any page, it is displaying as a blank page with no content. (Xamarin Forms)

  • Thread starter Thread starter Goodman Ngwenya
  • Start date Start date
G

Goodman Ngwenya

Guest
Timer Code on page load:

DateTime endTime = new DateTime(2019, 08, 28, 14, 00, 0);
public void StartCountDownTimer()
{
try
{
timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Elapsed += t_Tick;
TimeSpan ts = endTime - DateTime.Now;
lblCountDown.Text = ts.ToString("d' Days 'h' Hours 'm' Minutes 's' Seconds'");
timer.Start();
}
catch (Exception ex)
{
string Error = ex.Message;
}
}


System.Timers.Timer timer;
void t_Tick(object sender, EventArgs e)
{
TimeSpan ts = endTime - DateTime.Now;
string NewTimer = ts.ToString("d' Days 'h' Hours 'm' Minutes 's' Seconds'");
//txtCountDown.Text = NewTimer;
lblCountDown.Text = NewTimer;
if ((ts.TotalMilliseconds < 0) || (ts.TotalMilliseconds < 1000))
{
timer.Stop();
lblCountDown.Text = "The day has arrived";
}

}


Navigate Code using a button click on the same page:

private void ClickAboutTab(object sender, EventArgs e){await Navigation.PushAsync(new Page());}





Continue reading...
 
Back
Top