Are StopWatch.ElapsedTicks and StopWatch.Elapsed.Ticks always the same?

荒凉一梦 提交于 2019-11-29 16:02:22

问题


What does ElapsedTicks and Elapsed.Ticks in the StopWatch class mean? When could the meaning be different than intended?


回答1:


I just found out that ElapsedTicks in the StopWatch class doesn't mean real "ticks" if StopWatch.isHighResolution is True

Note(if isHighResolution is True):

Stopwatch ticks are different from DateTime..::.Ticks. Each tick in the DateTime..::.Ticks value represents one 100-nanosecond interval. Each tick in the ElapsedTicks value represents the time interval equal to 1 second divided by the Frequency.

You can do the math above or it seem you can use StopWatch.Elapsed.Ticks instead of StopWatch.ElapsedTicks




回答2:


Elapsed.Ticks / TimeSpan.TicksPerSecond == ElapsedTicks / Stopwatch.Frequency

Of course this may not exactly equal due to rounding, as Stopwatch ticks and TimeSpan ticks are measured in different units. Also, in case you executed the above code literally, obviously some ticks would elapse between taking the value of Elapsed.Ticks and that of ElapsedTicks.



来源:https://stackoverflow.com/questions/1017608/are-stopwatch-elapsedticks-and-stopwatch-elapsed-ticks-always-the-same

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!