예제 #1
0
        /// <summary>
        /// Adding multiple events to the timer will allow the events to run consecutively, though in no particular order.
        /// </summary>
        /// <param name="event"></param>
        /// <returns></returns>
        public override ServiceTimer AddEvent(ServiceTimerEventHandler @event)
        {
            Events += (s, e) =>
            {
                ++_runningTimers;
                try
                {
                    @event.Invoke(this, e);
                }
                catch (Exception error)
                {
                    Logger.Log(error);
                }

                if (--_runningTimers == 0)
                {
                    // Restart the timer immediately.
                    LocalTimer.Change(0, Timeout.Infinite);
                }
            };

            return(this);
        }
예제 #2
0
 public virtual ServiceTimer AddEvent(ServiceTimerEventHandler elapsedHandler)
 {
     Events += elapsedHandler;
     return(this);
 }