/// <summary> /// Start a timer instance /// </summary> internal void StartTimer(HiResTimerCallback callback) { lock (this) { // Kill timer. if (_TimerId > 0) { var unused = NativeMethods.timeKillEvent(_TimerId); _TimerId = 0; } // Must create callback or timer will crash. _callback = new HiResTimerCallback(callback); //Set the timer type flags var f = fuEvent.TIME_CALLBACK_FUNCTION | (AutoReset ? fuEvent.TIME_PERIODIC : fuEvent.TIME_ONESHOT); _TimerId = NativeMethods.timeSetEvent((uint)Interval, 0, _callback, UIntPtr.Zero, (uint)f); if (_TimerId == 0) { var ex = new Win32Exception(Marshal.GetLastWin32Error()); throw new Exception(ex.Message); } } }
internal static extern uint timeSetEvent(uint uDelay, uint uResolution, HiResTimerCallback lpTimeProc, UIntPtr dwUser, uint fuEvent);