开发者

is it possible to simulate a stopwatch with IsHighResolution = false when by default it's true?

开发者 https://www.devze.com 2022-12-15 00:27 出处:网络
Is it开发者_如何学编程 possible to simulate a stopwatch with IsHighResolution = false when by default it\'s true?Based on the documentation and a quick look in Reflector, I will offer a tentative no.

Is it开发者_如何学编程 possible to simulate a stopwatch with IsHighResolution = false when by default it's true?


Based on the documentation and a quick look in Reflector, I will offer a tentative no.

Here's the relevant part from the documentation:

The timer used by the Stopwatch class depends on the system hardware and operating system.

IsHighResolution is a read-only field which is initialized by the (static) type initializer via a call to the QueryPerformanceFrequency Win32 API function (apparently from kernel32.dll).

If there's any way of changing this, I can't think of it it.


Adding to what @Mark says, the documentation also says

Otherwise, IsHighResolution is false, which indicates that the Stopwatch timer is based on the system timer.

I guess it means, you could use a regular timer.
See if this article helps you.

EDIT: Looking into reflector, it seems that the code relies on DateTime.Ticks if it is not a high resolution timer to start/stop.

0

精彩评论

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

关注公众号