开发者

Simple C++ CLR stopwatch

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜