Forum Cross Platform with Xamarin
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.

Xamarin Timer is not Running as long as it says

I have developed the background service and use the Device.StartTimer to call my service. Its work fine on Emulator but the timer delay is not working properly on device. Please guide what is the problem in my timer code. Its not giving the 2min delay.

Device.StartTimer(TimeSpan.FromMinutes(2),()=>
{

                MessagingCenter.Send<string>("OK", "counterValue");
                //count += 1;
                return isRunningTimer;
            }
            );
Tagged:

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    Its work fine on Emulator but the timer delay is not working properly on device.

    Are you saying that your timer delays work well on emulators, but not on real devices?

    Besides, when we use a Timer, we should know that when we return true, the Timer repeats again, and vice versa.

    So, you can recheck the value of your variable isRunningTimer.

    Device.StartTimer(TimeSpan.FromSeconds(30), () =>
    {
        // Do something
    
        return true; // True = Repeat again, False = Stop the timer
    });
    
  • salmanpaulsalmanpaul Member ✭✭

    Timer is running but the interval is not correct. I have given the interval to 2 mins but its repeat differently please check the following values

    2020-09-28 17:20:20.000
    2020-09-28 17:20:51.000 (31 Sec)
    2020-09-28 17:20:52.000 (1 Sec)
    2020-09-28 17:22:20.000 (1min 28 Sec)
    2020-09-28 17:22:52.000 (32 Sec)
    2020-09-28 17:23:47.000 etc

  • salmanpaulsalmanpaul Member ✭✭

    Please guide i think their is a problem with the Device.Timer..

Sign In or Register to comment.