// timeBeginPeriod 사용 // 1ms 까지 설정가능 // 0.5ms Resolution 필요 시 NtSetTimerResolution 사용 #define TARGET_RESOLUTION 1 // 1-millisecond target resolution TIMECAPS tc; UINT wTimerRes; if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { // Error; application can't continue. } wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax); timeBeginPeriod(wTimerRes); // do your stuff here at approx. 1 ms timer resolution timeEndPeriod(wTimerRes);
[DllImport("ntdll.dll", SetLastError = true)] private static extern NtStatus NtSetTimerResolution( uint DesiredResolution, bool SetResolution, ref uint CurrentResolution); public static float SetTimerResolution(uint timerResolutionIn100nsUnits, bool doSet = true) { // 입출력값의 단위는 100ns // 1ms로 변경 시 SetTimerResolution(10000); // Enum NtStatus 는 별도 정의, 불필요 시 int로 대체 uint currentRes_100ns = 0; var result = NtSetTimerResolution(timerResolutionIn100nsUnits, doSet, ref currentRes_100ns); return currentRes_100ns; }