locked
Timer Speed is increasing on picker selection change RRS feed

  • Question

  • User252549 posted

    I am creating a timer which is working on a picker selection changed.Timer is working good until the times end to the "00:00:00".If i change the selection changed in the mid of time then the speed of timer is increased and if i again change selected index than timer run much fast. My problem is that timer should run on 1 sec dealy every time. I am sharing my code below. Thanks in advance for help.

               private async void GName_SelectedIndexChanged(object sender, EventArgs e)
                {
    
                lblEndTime.Text = "00:00:10";
    
                StartTimmer();
    
                }
    
             public void StartTimmer()
              {
            Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {
    
                Device.BeginInvokeOnMainThread(() =>
              {
                  TimeSpan timeSpan = TimeSpan.Parse(lblEndTime.Text);
    
                  timeSpan -= TimeSpan.FromSeconds(1);
    
                  if (lblEndTime.Text == "00:00:00")
                  {
                      returnValue = false;
    
                  }
                  else
                  {
                      lblEndTime.Text = Convert.ToString(timeSpan);
    
                  }
    
              });
    
                return returnValue;
            });
         }
    
    Thursday, July 30, 2020 5:21 PM

Answers

  • User89714 posted

    @Prashant3151 - If you only want one timer running, then you need to stop any existing timer before starting a new one. Alternatively, make use of any existing one rather than starting a new one.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, July 31, 2020 11:43 AM