Skip to content

Instantly share code, notes, and snippets.

@QuiltMeow
Last active July 5, 2022 17:40
Show Gist options
  • Save QuiltMeow/0a30868a69d86ee92110161986d6a37f to your computer and use it in GitHub Desktop.
Save QuiltMeow/0a30868a69d86ee92110161986d6a37f to your computer and use it in GitHub Desktop.
using System.Runtime.InteropServices;
namespace ClockResolution
{
public struct TimerResolution
{
public double periodMin;
public double periodMax;
public double periodCurrent;
}
public static class WindowsAPI
{
[DllImport("ntdll.dll", SetLastError = true)]
private static extern int NtQueryTimerResolution(out uint MaximumResolution, out uint MinimumResolution, out uint CurrentResolution);
public static TimerResolution queryTimerResolution()
{
NtQueryTimerResolution(out uint max, out uint min, out uint current);
return new TimerResolution()
{
periodMin = min / 10000D,
periodMax = max / 10000D,
periodCurrent = current / 10000D
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment