开发者

Simple C++ CLR stopwatch

开发者 https://www.devze.com 2023-02-10 16:36 出处:网络
For a project, I need to create a simple timer.A button is pressed to start the stopwatch until the button is pressed again.The running time is displayed until the stop button is pressed.It only needs

For a project, I need to create a simple timer. A button is pressed to start the stopwatch until the button is pressed again. The running time is displayed until the stop button is pressed. It only needs to be accurate to a hundredth of a second. My question is if the System.Diagnostics::Stopwatch clas开发者_开发百科s is the best choice for this application?


No, the Stopwatch class is intended for very precise (microseconds or better) measurements, not for accuracy (it may not be synchronized with wall time).

The best way to implement this is to start a regular UI timer and record the start time (perhaps DateTime.UtcNow). Whenever the timer ticks just update the display with the current time minus the start time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号