Forum Xamarin.Android

My timer is not working

I'm very new to programming, and I want to record sensor data, but I can't get my timer to work properly.

Tagged:

Answers

  • HamittirpanHamittirpan Member ✭✭✭✭

    @redrickjack Would you like to try a timer like this?

                 public partial class example : ContentPage
                  {
                      public example()
                      {
                          InitializeComponent();
                          timer(time: 60);  // 60 to 0
                      }
    
                private void timer(int time)
                     {
                          Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                          {
                              time -= 1;
                              _lblTime.Text = String.Format("{0}", time); // lblTime => label from xaml side
    
                              if (time == 0)
                              {
                                  time = 60;
                                  // todo 
                              }
                              return true;
                          });
                      }
                 }
    
Sign In or Register to comment.