Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        /// <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();
            }
        }
Beispiel #4
0
        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();
            }
        }
Beispiel #5
0
 public HighResolutionTimer(int interval)
 {
     Interval = interval;
     timeBeginPeriod(1);
     mHandler = new TimerEventDel(TimerCallback);
 }
Beispiel #6
0
 private static extern int timeSetEvent(int delay, int resolution, TimerEventDel handler, IntPtr user, int eventType);