Esempio n. 1
0
        /// <summary>
        /// Schedules an action to be invoked after an delay.
        /// </summary>
        /// <param name="scheduler">The scheduler</param>
        /// <param name="delay">The time period that has to pass before the action is invoked.</param>
        /// <param name="action">The action to perform.</param>
        /// <returns>A cancelable that can be used to cancel the action from being executed</returns>
        public static ICancelable ScheduleOnceCancelable(this IActionScheduler scheduler, TimeSpan delay, Action action)
        {
            var cancelable = new Cancelable(scheduler);

            scheduler.ScheduleOnce(delay, action, cancelable);
            return(cancelable);
        }
Esempio n. 2
0
        /// <summary>
        /// Schedules an action to be invoked after an delay.
        /// </summary>
        /// <param name="scheduler">The scheduler</param>
        /// <param name="millisecondsDelay">The time in milliseconds that has to pass before the action is invoked.</param>
        /// <param name="action">The action to perform.</param>
        /// <returns>A cancelable that can be used to cancel the action from being executed</returns>
        public static ICancelable ScheduleOnceCancelable(this IActionScheduler scheduler, int millisecondsDelay, Action action)
        {
            var cancelable = new Cancelable(scheduler);

            scheduler.ScheduleOnce(millisecondsDelay, action, cancelable);
            return(cancelable);
        }
Esempio n. 3
0
        private void InternalCancelAfter(TimeSpan delay)
        {
            ThrowIfDisposed();
            if (_source.IsCancellationRequested)
            {
                return;
            }

            //If the scheduler is using the system time, we can optimize for that
            if (_scheduler is IDateTimeOffsetNowTimeProvider)
            {
                //Use the built in functionality on CancellationTokenSource which is
                //likely more lightweight than using the scheduler
                _source.CancelAfter(delay);
            }
            else
            {
                _scheduler.ScheduleOnce(delay, () => _source.Cancel(), this);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Schedules an action to be invoked after an delay.
 /// The action will be wrapped so that it completes inside the currently active actor if it is called from within an actor.
 /// <remarks>Note! It's considered bad practice to use concurrency inside actors, and very easy to get wrong so usage is discouraged.</remarks>
 /// </summary>
 /// <param name="scheduler">The scheduler</param>
 /// <param name="millisecondsDelay">The time in milliseconds that has to pass before the action is invoked.</param>
 /// <param name="action">The action to perform.</param>
 /// <param name="cancelable">OPTIONAL. A cancelable that can be used to cancel the action from being executed. Defaults to <c>null</c></param>
 public static void ScheduleOnce(this IActionScheduler scheduler, int millisecondsDelay, Action action, ICancelable cancelable = null)
 {
     scheduler.ScheduleOnce(TimeSpan.FromMilliseconds(millisecondsDelay), action, cancelable);
 }