public object StartTimer(TimeSpan interval, Action callback) { UnmanagedMethods.TimerProc timerDelegate = (UnmanagedMethods.TimerProc) ((hWnd, uMsg, nIDEvent, dwTime) => callback()); IntPtr handle = UnmanagedMethods.SetTimer( IntPtr.Zero, IntPtr.Zero, (uint)interval.TotalMilliseconds, timerDelegate); this.timerCallbacks.Add(handle, timerDelegate); return(handle); }
public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action callback) { UnmanagedMethods.TimerProc timerDelegate = (hWnd, uMsg, nIDEvent, dwTime) => callback(); IntPtr handle = UnmanagedMethods.SetTimer( IntPtr.Zero, IntPtr.Zero, (uint)interval.TotalMilliseconds, timerDelegate); // Prevent timerDelegate being garbage collected. _delegates.Add(timerDelegate); return(Disposable.Create(() => { _delegates.Remove(timerDelegate); UnmanagedMethods.KillTimer(IntPtr.Zero, handle); })); }
public TimerDisposable(IntPtr handle, UnmanagedMethods.TimerProc timerDelegate, List <Delegate> delegates) { this.handle = handle; this.timerDelegate = timerDelegate; this.delegates = delegates; }