HiResTimerSpinWaitThreshold Property

Gets or sets the threshold value, in milliseconds, determining when to transition from sleeping to spinning while waiting for the next Elapsed event.
Default value: 16.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public int SpinWaitThreshold { get; set; }

Property Value

Int32

Remarks

  Caution

For advanced users only. When the value of this property is too high, the timer thread may never sleep, causing high CPU usage unnecessarily. When the value is too low, the timer may not be able to achieve high precision. On Windows, Thread.Sleep lasts at least about 15.5 ms by default, unless configured otherwise by WinMM or other means. The default value of this property is adjusted to this behavior.

On non-Windows platforms it's usually safe to lower the value of this property to 2.

On Windows you can use the native timeBeginPeriod Windows API function to set the system timer resolution. Please note though, that this setting may affect the whole system and may increase power consumption. Even when running on Windows 10 20H1 or later, where the function is a process-wide setting rather than a system-wide setting, it may affect the timers of the whole application.

Exceptions

ArgumentOutOfRangeExceptionvalue is zero or negative.

See Also