Exemple #1
0
        /// <summary>Initializes a new instance of the <see cref="ThrottledAction"/> class.</summary>
        /// <param name="action">The action that should be throttled.</param>
        /// <param name="mode">Defines the throttling mode.</param>
        /// <param name="delayTime">The delay time.</param>
        /// <exception cref="ArgumentNullException">The argument action must not be null.</exception>
        public ThrottledAction(Action action, ThrottledActionMode mode, TimeSpan delayTime)
        {
            taskScheduler = SynchronizationContext.Current != null?TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Default;

            this.action    = action ?? throw new ArgumentNullException(nameof(action));
            this.mode      = mode;
            this.delayTime = delayTime;
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ThrottledAction"/> class.
 /// </summary>
 /// <param name="action">The action that should be throttled.</param>
 /// <param name="mode">Defines the throttling mode.</param>
 /// <param name="delayTime">The delay time.</param>
 /// <exception cref="ArgumentNullException">The argument action must not be null.</exception>
 public ThrottledAction(Action action, ThrottledActionMode mode, TimeSpan delayTime)
 {
     if (action == null) { throw new ArgumentNullException(nameof(action)); }
     this.taskScheduler = SynchronizationContext.Current != null ? TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Default;
     this.timer = new Timer(TimerCallback, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
     this.action = action;
     this.mode = mode;
     this.delayTime = delayTime;
 }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ThrottledAction"/> class.
        /// </summary>
        /// <param name="action">The action that should be throttled.</param>
        /// <param name="mode">Defines the throttling mode.</param>
        /// <param name="delayTime">The delay time.</param>
        /// <exception cref="ArgumentNullException">The argument action must not be null.</exception>
        public ThrottledAction(Action action, ThrottledActionMode mode, TimeSpan delayTime)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            this.taskScheduler = SynchronizationContext.Current != null?TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Default;

            this.timer     = new Timer(TimerCallback, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
            this.action    = action;
            this.mode      = mode;
            this.delayTime = delayTime;
        }
Exemple #4
0
        /// <summary> Initializes a new instance of the <see cref="ThrottledAction"/> class. </summary>
        /// <param name="_action">The action that should be throttled.</param>
        /// <param name="_mode">Defines the throttling mode.</param>
        /// <param name="_delayTime">The delay time.</param>
        /// <exception cref="ArgumentNullException">The argument action must not be null.</exception>
        public ThrottledAction(Action _action, ThrottledActionMode _mode, TimeSpan _delayTime)
        {
            if (null == _action)
            {
                throw new ArgumentNullException(nameof(_action));
            }

            m_TaskScheduler = SynchronizationContext.Current != null?TaskScheduler.FromCurrentSynchronizationContext() : TaskScheduler.Default;

            m_Timer     = new Timer(TimerCallback);
            m_Action    = _action;
            m_Mode      = _mode;
            m_DelayTime = _delayTime;
        }