コード例 #1
0
 /// <summary>
 /// Checks if an action is scheduled.
 /// </summary>
 /// <param name="action">The action in question.</param>
 /// <returns>
 /// True if the action is scheduled, otherwise false.
 /// </returns>
 public bool isScheduled(NSFTimerAction action)
 {
     lock (threadMutex)
     {
         return(actions.Contains(action));
     }
 }
コード例 #2
0
        /// <summary>
        /// Schedules an action with the timer.
        /// </summary>
        /// <param name="action">The action to schedule.</param>
        /// <param name="delayTime">The delay time before the action should execute.</param>
        /// <param name="repeatTime">The repeat time if the action is periodic, or 0 if the action is non-periodic.</param>
        public void scheduleAction(NSFTimerAction action, NSFTime delayTime, NSFTime repeatTime)
        {
            action.ExecutionTime = CurrentTime + delayTime;
            action.RepeatTime    = repeatTime;
            action.DelayTime     = delayTime;

            scheduleAction(action);
        }
コード例 #3
0
 /// <summary>
 /// Executes the specified action, and reschedules it if a repeat time is specified.
 /// </summary>
 /// <param name="action">The action to execute.</param>
 private void executeAction(NSFTimerAction action)
 {
     // Guard a bad action from taking down timer thread
     try
     {
         action.execute();
     }
     catch (Exception exception)
     {
         handleException(new Exception(action.Name + " action execution exception", exception));
     }
 }
コード例 #4
0
        /// <summary>
        /// Schedules an action to execute at its previously designated execution time.
        /// </summary>
        /// <param name="action">The action to schedule.</param>
        public void scheduleAction(NSFTimerAction action)
        {
            lock (threadMutex)
            {
                // Do not schedule any actions if terminating or terminated (i.e. not ready)
                if (TerminationStatus != NSFThreadTerminationStatus.ThreadReady)
                {
                    return;
                }

                insertAction(action);

                // Set next timeout if action was inserted in the front of the list
                if (action == actions.First.Value)
                {
                    timer.setNextTimeout(action.ExecutionTime);
                }
            }
        }
コード例 #5
0
        private void insertAction(NSFTimerAction action)
        {
            // Make sure action is not already in list
            actions.Remove(action);

            // Insert into list based on execution time order
            // Actions with equal execution times are executed in FIFO order
            LinkedListNode <NSFTimerAction> nextNode = actions.First;

            while (nextNode != null)
            {
                if (action.ExecutionTime < nextNode.Value.ExecutionTime)
                {
                    actions.AddBefore(nextNode, action);
                    return;
                }
                nextNode = nextNode.Next;
            }

            // Insert action at end of list if not alread inserted
            actions.AddLast(action);
        }
コード例 #6
0
        /// <summary>
        /// Unschedules a previously scheduled action.
        /// </summary>
        /// <param name="action">The action to unschedule.</param>
        /// <remarks>
        /// Unscheduling an action that is not currently scheduled has no effect.
        /// </remarks>
        public void unscheduleAction(NSFTimerAction action)
        {
            lock (threadMutex)
            {
                if (actions.Count != 0)
                {
                    if (action == actions.First.Value)
                    {
                        actions.Remove(action);

                        if (actions.Count != 0)
                        {
                            timer.setNextTimeout(actions.First.Value.ExecutionTime);
                        }
                    }
                    else
                    {
                        actions.Remove(action);
                    }
                }
            }
        }
コード例 #7
0
        private void insertAction(NSFTimerAction action)
        {
            // Make sure action is not already in list
            actions.Remove(action);

            // Insert into list based on execution time order
            // Actions with equal execution times are executed in FIFO order
            LinkedListNode<NSFTimerAction> nextNode = actions.First;
            while (nextNode != null)
            {
                if (action.ExecutionTime < nextNode.Value.ExecutionTime)
                {
                    actions.AddBefore(nextNode, action);
                    return;
                }
                nextNode = nextNode.Next;
            }

            // Insert action at end of list if not alread inserted
            actions.AddLast(action);
        }
コード例 #8
0
 /// <summary>
 /// Executes the specified action, and reschedules it if a repeat time is specified.
 /// </summary>
 /// <param name="action">The action to execute.</param>
 private void executeAction(NSFTimerAction action)
 {
     // Guard a bad action from taking down timer thread
     try
     {
         action.execute();
     }
     catch (Exception exception)
     {
         handleException(new Exception(action.Name + " action execution exception", exception));
     }
 }
コード例 #9
0
        /// <summary>
        /// Unschedules a previously scheduled action.
        /// </summary>
        /// <param name="action">The action to unschedule.</param>
        /// <remarks>
        /// Unscheduling an action that is not currently scheduled has no effect.
        /// </remarks>
        public void unscheduleAction(NSFTimerAction action)
        {
            lock (threadMutex)
            {
                if (actions.Count != 0)
                {
                    if (action == actions.First.Value)
                    {
                        actions.Remove(action);

                        if (actions.Count != 0)
                        {
                            timer.setNextTimeout(actions.First.Value.ExecutionTime);
                        }
                    }
                    else
                    {
                        actions.Remove(action);
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Schedules an action with the timer.
        /// </summary>
        /// <param name="action">The action to schedule.</param>
        /// <param name="delayTime">The delay time before the action should execute.</param>
        /// <param name="repeatTime">The repeat time if the action is periodic, or 0 if the action is non-periodic.</param>
        public void scheduleAction(NSFTimerAction action, NSFTime delayTime, NSFTime repeatTime)
        {
            action.ExecutionTime = CurrentTime + delayTime;
            action.RepeatTime = repeatTime;
            action.DelayTime = delayTime;

            scheduleAction(action);
        }
コード例 #11
0
        /// <summary>
        /// Schedules an action to execute at its previously designated execution time.
        /// </summary>
        /// <param name="action">The action to schedule.</param>
        public void scheduleAction(NSFTimerAction action)
        {
            lock (threadMutex)
            {
                // Do not schedule any actions if terminating or terminated (i.e. not ready)
                if (TerminationStatus != NSFThreadTerminationStatus.ThreadReady)
                {
                    return;
                }

                insertAction(action);

                // Set next timeout if action was inserted in the front of the list
                if (action == actions.First.Value)
                {
                    timer.setNextTimeout(action.ExecutionTime);
                }
            }
        }
コード例 #12
0
 /// <summary>
 /// Checks if an action is scheduled.
 /// </summary>
 /// <param name="action">The action in question.</param>
 /// <returns>
 /// True if the action is scheduled, otherwise false.
 /// </returns>
 public bool isScheduled(NSFTimerAction action)
 {
     lock (threadMutex)
     {
         return actions.Contains(action);
     }
 }