Example #1
0
    /**
     * Register an event handler to listen to events of type /eventName/,
     * from the given sender only.
     */
    public void RegisterClockEvent(EventDefine eventName, ClockEventHandler handler, long startTimeTicks, long timeSpanSeconds)
    {
        //when you regist a clock event it may has been elapse some timeSpan
        DateTime clockBegin  = new DateTime(startTimeTicks);
        DateTime currentDate = DateTime.Now;

        long     elapsedTicks = currentDate.Ticks - clockBegin.Ticks;
        TimeSpan elapsedSpan  = new TimeSpan(elapsedTicks);

        long totalSeconds = Convert.ToInt64(elapsedSpan.TotalSeconds);

        // there is /count/ timeSpan between start time and now
        long count = totalSeconds / timeSpanSeconds;

        for (long i = 0; i < count; i++)
        {
            handler(eventName);
        }

        // reset start time ticks to a reason value
        startTimeTicks += count * timeSpanSeconds * Global.SECOND_TO_TICKS;

        if (!ContainClockEvent(eventName))
        {
            m_ClockEvents.Add(new ClockEventClass(eventName, handler, startTimeTicks, timeSpanSeconds));
        }
        else
        {
            int index = GetClockEventIndex(eventName);
            m_ClockEvents[index] = new ClockEventClass(eventName, handler, startTimeTicks, timeSpanSeconds);
        }
    }
Example #2
0
        protected virtual void OnAlarm(ClockArgs e)
        {
            ClockEventHandler handler = Alarm;

            if (handler != null)
            {
                // Invokes the delegates.
                handler(this, e);
            }
        }
Example #3
0
 public ClockEventClass(ClockEventClass copy)
 {
     m_Name = copy.m_Name; m_LastUpdateTime = copy.m_LastUpdateTime; m_TimeSpan = copy.m_TimeSpan; m_handler = copy.m_handler;
 }
Example #4
0
 public ClockEventClass(EventDefine name, ClockEventHandler handler, long startTime, long timeSpan)
 {
     m_Name = name; m_LastUpdateTime = startTime; m_TimeSpan = timeSpan; m_handler = handler;
 }
Example #5
0
    /**
     * Register an event handler to listen to events of type /eventName/,
     * from the given sender only.
     */
    public void RegisterClockEvent(EventDefine eventName, ClockEventHandler handler, long startTimeTicks, long timeSpanSeconds)
    {
        //when you regist a clock event it may has been elapse some timeSpan
        DateTime clockBegin = new DateTime(startTimeTicks);
        DateTime currentDate = DateTime.Now;

        long elapsedTicks = currentDate.Ticks - clockBegin.Ticks;
        TimeSpan elapsedSpan = new TimeSpan(elapsedTicks);

        long totalSeconds = Convert.ToInt64(elapsedSpan.TotalSeconds);

        // there is /count/ timeSpan between start time and now
        long count = totalSeconds / timeSpanSeconds;
        for( long i = 0; i < count ; i++ )
        {
            handler(eventName);
        }

        // reset start time ticks to a reason value
        startTimeTicks += count * timeSpanSeconds * Global.SECOND_TO_TICKS;

        if( !ContainClockEvent(eventName))
        {
            m_ClockEvents.Add(new ClockEventClass(eventName, handler, startTimeTicks, timeSpanSeconds));
        }
        else
        {
            int index = GetClockEventIndex(eventName);
            m_ClockEvents[index] = new ClockEventClass(eventName, handler, startTimeTicks, timeSpanSeconds);
        }
    }
Example #6
0
 public ClockEventClass(EventDefine name, ClockEventHandler handler, long startTime, long timeSpan)
 {
     m_Name = name; m_LastUpdateTime = startTime; m_TimeSpan = timeSpan; m_handler = handler;
 }