private CancellableAction DequeueAction() { CancellableAction cancellableAction = actions[0]; actions.RemoveAt(0); return(cancellableAction); }
public IDisposable ScheduleTask(TimeSpan timeSpan, Action action) { CancellableAction cancellableAction = new CancellableAction(action); queue.Enqueue(CurrentTime + timeSpan, cancellableAction); return(new Disposable(() => cancellableAction.Cancel())); }
public static ActionTask Run(CancellableAction doThis, CancellationToken cancellationToken = null, TaskScheduler scheduler = null) { var task = new ActionTask(doThis, cancellationToken, scheduler); task.Start(); return(task); }
/// <summary> /// Creates an unstarted Task. /// </summary> /// <param name="doThis"></param> /// <param name="cancellationToken"></param> /// <param name="scheduler"></param> internal ActionTask(CancellableAction doThis, CancellationToken cancellationToken = null, TaskScheduler scheduler = null) : base(cancellationToken, scheduler) { if (doThis == null) { throw new ArgumentNullException("doThis"); } _userWork = doThis; }
/// <summary> /// Creates an unstarted Task. /// </summary> /// <param name="doThis"></param> /// <param name="scheduler"></param> internal ActionTask(Action doThis, TaskScheduler scheduler = null) : base(CancellationToken.None, scheduler) { if (doThis == null) { throw new ArgumentNullException("doThis"); } _userWork = token => doThis(); }
/// <summary> /// Enforces execution of particular method. It will be retried on each garbage collect. /// </summary> /// <param name="action"></param> /// <param name="token"></param> /// <returns></returns> private void ShouldExecute(CancellableAction action, CancellationToken token) { try { action(token); return; } catch { } _actions.Add(action); }
internal static ActionTask BuildContinuation(Task antecedent, CancellableAction doThis, CancellationToken cancellationToken, TaskScheduler scheduler = null) { var continuation = new ActionTask(doThis, cancellationToken, scheduler); continuation.SetStatusToUnstartedContinuation(); TaskContinuationManager.RegisterContinuation(antecedent, continuation); return(continuation); }
/// <summary> /// Enforces execution of particular method. It will be retried on each garbage collect. /// </summary> /// <param name="action"></param> /// <param name="token"></param> /// <returns></returns> private async Task ShouldExecute(CancellableAction action, CancellationToken token) { try { await action(token); return; } catch { } _actions.Add(action); }
/// <inheritdoc /> public AsyncCancellableCommand(CancellableAction <object?> action, Predicate <object?> canExecute) : base(canExecute) { if (action is null) { throw new ArgumentNullException(nameof(action)); } AllowMultipleExecutions = false; _action = action; CommandStarted += (sender, args) => _cancelSource = new CancellationTokenSource(); _cancelSource = new CancellationTokenSource(); }
public IDisposable ScheduleTask(TimeSpan timeSpan, Action action) { CancellableAction cancellableAction = new CancellableAction(CurrentTime + timeSpan, action); EnqueueAction(cancellableAction); if (timeSpan == TimeSpan.Zero && !isProcessing && !isImmediateProcessingDisabled) { ProcessDueOperations(); } return(new Disposable(() => cancellableAction.Cancel())); }
private CancellableAction <T> Wrap(CancellableAction <T> act) { return((task, _token, _progress) => { if (_progress.HasFinished) //was it cancelled prior to calling. { return; } act(task, _token, _progress); if (_progress.HasFinished == false) { _progress.SetAsFinished(); } }); }
private void EnqueueAction(CancellableAction cancellableAction) { int i = 0; foreach (CancellableAction action in actions) { if (cancellableAction.TimeSpan < action.TimeSpan) { break; } i++; } actions.Insert(i, cancellableAction); }
public QueuedTask <T> QueueTask(CancellableAction <T> act) { if (_threadstop) { return(null); } lock (Queue) { if (_threadstop) { return(null); } var pd = new ProgressDesciber(); var queued = new QueuedTask <T>(act); Queue.Enqueue(queued); queued.State = TaskState.Queued; FireTaskQueued(queued); res.Set(); return(queued); } }
public QueuedTask(CancellableAction <T> action) { Action = Wrap(action); Progress = new ProgressDesciber(); Token = Progress.Token; }
public static ActionTask New(CancellableAction doThis, CancellationToken cancellationToken = null, TaskScheduler scheduler = null) { return(new ActionTask(doThis, cancellationToken, scheduler)); }
/// <inheritdoc /> public AsyncCancellableCommand(CancellableAction action) : this(action, AlwaysExecute) { }
/// <inheritdoc /> public AsyncCancellableCommand(CancellableAction action, Predicate <object?> canExecute) : this((ct, _) => action(ct), canExecute) { }
public QueuedTask(CancellableAction <T> action, ProgressDesciber progress, CancellationToken token) { Action = Wrap(action); Progress = progress; Token = token; }
protected override void ExecuteUserWork(CancellationToken cancellationToken) { _userWork(cancellationToken); _userWork = null; }
public IDisposable ScheduleTask(TimeSpan timeSpan, Action action) { CancellableAction cancellableAction = new CancellableAction(action); queue.Enqueue(CurrentTime + timeSpan, cancellableAction); return new Disposable(() => cancellableAction.Cancel()); }
public static ActionTask Run(CancellableAction doThis, CancellationToken cancellationToken = null) { return(Task.Run(doThis, cancellationToken, TaskScheduler.DefaultScheduler)); }