Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Timer Speed is increasing on picker selection change

Prashant3151Prashant3151 USMember ✭✭
edited July 30 in Xamarin.Forms

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;
        });
     }

Best Answer

Answers

Sign In or Register to comment.