private TimerEventDel mHandler; // NOTE: declare at class scope so garbage collector doesn't release it!!! public AccurateTimer(Action action, int delay) { mAction = action; timeBeginPeriod(1); mHandler = new TimerEventDel(TimerCallback); mTimerId = timeSetEvent(delay, 0, mHandler, IntPtr.Zero, EVENT_TYPE); }
private readonly TimerEventDel _handler; //Needs to be here so the Garbage Collector won't collect it. #endregion #region Methods public Timer(Form form, Action action, int delay) { _delay = delay; _action = action; _form = form; _handler = TimerCallback; //timeBeginPeriod(1); //_handler = TimerCallback; //_timerId = timeSetEvent(delay, 0, _handler, IntPtr.Zero, EventType); }
/// <summary> /// Cria um novo timer de precisão /// </summary> /// <param name="form">Formulário</param> /// <param name="action">Ação</param> /// <param name="delay">Intervalo</param> /// <param name="startPaused">Indica se o timer iniciará pausado ou não</param> public AccurateTimer(Form form, Action action, int delay, bool startPaused = false) { mForm = form; mAction = action; mDelay = delay; mutex = new object(); mHandler = new TimerEventDel(TimerCallback); if (!startPaused) { Start(); } }
public AccurateTimer(Form form, Action action, int delay, bool fCalculateElapsedTime = false) { //semaphore = new Semaphore(1, 1); if (fCalculateElapsedTime == true) { stopWatch = new Stopwatch(); } mAction = action; mForm = form; timeBeginPeriod(1); mHandler = new TimerEventDel(TimerCallback); mTimerId = timeSetEvent(delay, 0, mHandler, IntPtr.Zero, EVENT_TYPE); if (fCalculateElapsedTime == true) { stopWatch.Start(); } }
public HighResolutionTimer(int interval) { Interval = interval; timeBeginPeriod(1); mHandler = new TimerEventDel(TimerCallback); }
private static extern int timeSetEvent(int delay, int resolution, TimerEventDel handler, IntPtr user, int eventType);