/// <summary> /// Schedules an action to be executed. /// </summary> /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> /// <param name="state">State passed to the action to be executed.</param> /// <param name="action">Action to be executed.</param> /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception> public override IDisposable Schedule <TState>(TState state, Func <IScheduler, TState, IDisposable> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } var workItem = new UserWorkItem <TState>(this, state, action); workItem.CancelQueueDisposable = Cal.QueueUserWorkItem(
private IDisposable ScheduleSlow <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action) { var userWorkItem = new UserWorkItem <TState>(this, state, action); var res = ThreadPoolTimer.CreateTimer( tpt => userWorkItem.Run(), dueTime); userWorkItem.CancelQueueDisposable = res.AsDisposable(); return(userWorkItem); }
/// <summary> /// Schedules an action to be executed. /// </summary> /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> /// <param name="state">State passed to the action to be executed.</param> /// <param name="action">Action to be executed.</param> /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception> public override IDisposable Schedule <TState>(TState state, Func <IScheduler, TState, IDisposable> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } var workItem = new UserWorkItem <TState>(this, state, action); workItem.CancelQueueDisposable = s_cal.QueueUserWorkItem( closureWorkItem => ((UserWorkItem <TState>)closureWorkItem).Run(), workItem); return(workItem); }
/// <summary> /// Schedules an action to be executed. /// </summary> /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> /// <param name="state">State passed to the action to be executed.</param> /// <param name="action">Action to be executed.</param> /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception> public override IDisposable Schedule <TState>(TState state, Func <IScheduler, TState, IDisposable> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } var userWorkItem = new UserWorkItem <TState>(this, state, action); var res = ThreadPool.RunAsync( iaa => userWorkItem.Run(), Priority, Options); userWorkItem.CancelQueueDisposable = res.AsDisposable(); return(userWorkItem); }
/// <summary> /// Schedules an action to be executed after dueTime, using a System.Threading.Timer object. /// </summary> /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam> /// <param name="state">State passed to the action to be executed.</param> /// <param name="action">Action to be executed.</param> /// <param name="dueTime">Relative time after which to execute the action.</param> /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns> /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception> public override IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } var dt = Scheduler.Normalize(dueTime); if (dt.Ticks == 0) { return(Schedule(state, action)); } var workItem = new UserWorkItem <TState>(this, state, action); workItem.CancelQueueDisposable = s_cal.StartTimer( closureWorkItem => ((UserWorkItem <TState>)closureWorkItem).Run(), workItem, dt); return(workItem); }