Skip to content

Task.Delay and System.Threading.Timer wrong resolution description #7706

@kirsan31

Description

@kirsan31

System.Threading.Timer https://docs.microsoft.com/en-us/dotnet/api/system.threading.timer?view=net-6.0

The Timer class has the same resolution as the system clock. This means that if the period is less than the resolution of the system clock, the TimerCallback delegate will execute at intervals defined by the resolution of the system clock, which is approximately 15 milliseconds on Windows 7 and Windows 8 systems.

Task.Delay https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.delay?view=net-6.0

This method depends on the system clock. This means that the time delay will approximately equal the resolution of the system clock if the millisecondsDelay argument is less than the resolution of the system clock, which is approximately 15 milliseconds on Windows systems.

This is not true (on windows) both of them doesn't respect system timer resolution below 15 milliseconds. After timeBeginPeriod(1) or NtSetTimerResolution(5000, true, out _) the resolution of System.Threading.Timer and Task.Delay still remains ~15 milliseconds :(

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions