How to make an accurate decimal Timer?

后端 未结 2 1790
没有蜡笔的小新
没有蜡笔的小新 2020-12-12 03:19

I\'m pretty frustrated about this one ..

I have a timer called timer1 and a text box called TimeElapsedTextBox and a double va

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 04:05

    Instead of using a timer, record the start time using DateTime.Now and then subtract the current time (DateTime.Now) from the start time. This will give you a more accurate timer as it uses the system clock instead which isn't affected so much by CPU performance.

    Alternatively you can use System.Diagnostics.Stopwatch which does this for you.

    You can still use an ordinary timer with an interval of less than a second to refresh the label displaying the time.

提交回复
热议问题