Timer start time and end time calculation gives 4 secs extra

后端 未结 2 1524
-上瘾入骨i
-上瘾入骨i 2021-01-24 19:49

i am working on WP8 , i am using timer where i am calulating the total time.

This is how i am doing it:

timer = new DispatcherTimer();
 timer.Interval =          


        
相关标签:
2条回答
  • 2021-01-24 20:18

    So you are counting ticks with this timer and expecting after 60 ticks of 1s, exactly 1 minute will have passed.

    It doesn't work like that. Other stuff is happening in the application, and .NET never assures it will be exactly one second between ticks.

    If you want accuracy, use System.Diagnostics.Stopwatch which gives a very accurate elapsed time based on the system clock.

    0 讨论(0)
  • 2021-01-24 20:18

    You are using the wrong tool for calculating time. You should StopWatch instead of timer. Timer is used to do something that is meant to happen at a regular interval.

    0 讨论(0)
提交回复
热议问题