Timer start time and end time calculation gives 4 secs extra

后端 未结 2 1523
-上瘾入骨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.

提交回复
热议问题