void CancelReadPackagesTask() { if (task != null) { task.Cancel(); } }
/// <summary> /// Cancels all tasks. /// </summary> public void CancelAll(object reason) { ITask[] tasks; lock (_sync) { tasks = _queue.ToArray(); _queue.Clear(); _shadowQueue.Clear(); _count = 0; _currentTask = null; } // cancel all tasks in the reverse order, so that new tasks // are not started as the currently executed one is finished with cancel: if (tasks.Length > 0) { for (int i = tasks.Length - 1; i >= 0; i--) { ITask task = tasks[i]; task.StatusChanged -= TaskStatusChanged; task.Cancel(reason); } } lock (_sync) { _startEvent.Set(); } }
public override void HandleKeyUp() { if (!IsPressed) { return; } task?.Cancel(); base.HandleKeyUp(); }
/// <summary> /// Cancels current task. /// </summary> public void Cancel(object reason) { if (_currentTask != null) { _currentTask.Cancel(reason); _currentTask.StatusChanged -= TaskStatusChanged; } ClearCurrent(); }
/// <summary> /// Cancels selected task. /// </summary> public void Cancel(ITask task, object reason) { if (task == null) { throw new ArgumentNullException("task"); } task.Cancel(reason); RemoveTask(task); }
public void Stop() { if (task != null) { task.Cancel (); task = null; } if (currentCheckForUpdatesTask != null) { currentCheckForUpdatesTask.Dispose (); currentCheckForUpdatesTask = null; } }
public override ITask SetInterval(int delayFrames, int intervalFrames, Action tick) { ITask task = null; task = SetTimeout(delayFrames, () => { task = SetInterval(intervalFrames, tick); tick(); }); // ReSharper disable once ImplicitlyCapturedClosure return(new Task(() => task.Cancel())); }
public virtual ITask SetTimeout(int frames, Action action) { ITask task = null; task = SetInterval(frames, () => { // ReSharper disable once AccessToModifiedClosure // ReSharper disable once PossibleNullReferenceException task.Cancel(); action(); }); return(task); }
public static ITask Run( this ITaskRunner runner , ref ITask task , IEnumerator enumerator ) { if (task != null && task.IsRunning()) { task.Cancel(); } task = runner.Run(enumerator); return(task); }
private void RescheduleGravity() { gravityTask?.Cancel(); if (game.IsOver) { return; } var delay = GameBoy.LevelSpeed[game.Stats.Level]; gravityTask = scheduler.SetTimeout(delay, () => { ApplyGravity(); RescheduleGravity(); }); }
protected virtual void RunTask(object item) { Recorder.Trace(2L, TraceType.InfoTrace, new object[] { "Executor.RunTask Item:", item, "IsCancelled:", this.IsCancelled }); if (!this.IsCancelled) { ITask task = null; try { long timestamp = this.Policy.Recorder.Timestamp; task = (Activator.CreateInstance(this.TaskType) as ITask); task.State = new SearchTaskContext { TaskContext = this.TaskContext, Executor = this, Item = item }; task.Execute(this.defaultQueueDelay, this.defaultTimeout); task.Complete(this.defaultQueueDelay, this.defaultTimeout); long num = this.Policy.Recorder.Timestamp - timestamp; Interlocked.Increment(ref this.itemCount); Interlocked.Add(ref this.totalDuration, num); IList list = item as IList; int num2 = 1; if (list != null) { num2 = list.Count; } this.batchDurations.Add(new Tuple <long, long, long>(timestamp, num, (long)num2)); } catch (SearchException ex) { if (task != null) { task.Cancel(); } this.Cancel(ex); Recorder.Trace(2L, TraceType.ErrorTrace, "Executor.RunTask Failed Error:", ex); } } }
/// <summary> /// Cancels all tasks. /// </summary> public void CancelAll(object reason) { ITask[] tasks = _queue.ToArray(); _queue.Clear(); _count = 0; _currentTask = null; // cancel all tasks in the reverse order, so that new tasks // are not started as the currently executed one is finished with cancel: if (tasks.Length > 0) { for (int i = tasks.Length - 1; i >= 0; i--) { ITask task = tasks[i]; task.StatusChanged -= TaskStatusChanged; task.Cancel(reason); } Event.Invoke(QueueEmpty, this, new TaskExecutorEventArgs(this, !_started)); } }
private async void Command_Execute(IHost sender, ExecuteEventArgs e) { this.Host = sender; try { if (e.View.GetCurrentId() != null) { idNote = Aliquo.Core.Convert.ValueToInt64(e.View.GetCurrentId()); Aliquo.Core.Models.Note note = await this.Host.Documents.GetNoteAsync(idNote); // The assistant is configured System.Text.StringBuilder settings = new System.Text.StringBuilder(); settings.AppendFormat("<? NAME='Email' TYPE='STRING' TEXT='E-mail' STYLE='EMAIL' REQUIRED=1>"); settings.AppendFormat("<? NAME='Subject' TYPE='STRING' TEXT='Subject' DEFAULT='Delivery of delivery note material {0}'>", Aliquo.Core.Formats.SerialAndNumber(note.SerialCode, note.Number)); settings.AppendFormat("<? NAME='Message' TYPE='STRING' TEXT='MensMessageaje' DEFAULT='Enclosed we send you information about the delivery of the delivery note {0}.' ROWS=9 LENGTH=2048>", Aliquo.Core.Formats.SerialAndNumber(note.SerialCode, note.Number)); ITask task = this.Host.Management.Views.WizardCustom(PlugInTitle, string.Empty, settings.ToString()); task.Finishing += ExecuteWizardFinishingAsync; // Check that the parameter is filled configEmail = this.Host.Configuration.GetParameter("EMAIL_SERVER"); if (string.IsNullOrEmpty(configEmail)) { task.Cancel(); Message.Show("Confirm that the configuration of the EMAIL_SERVER parameter is complete.", "EMAIL_SERVER parameter"); } } } catch (Exception ex) { sender.Management.Views.ShowException(ex); } }
private void manageTask(ITask value) { StartingTask.Raise(this, new TaskmanagerEventArgs() { Task = value }); TaskEntry entry; if (QueuedTasks.TryGetValue(value.UniqueId, out entry)) { if (entry.State == "pending") { Exception exception = null; try { CurrentTasks.TryAdd(value.UniqueId, value); TaskEntry s; QueuedTasks.TryRemove(value.UniqueId, out s); StartedTask.Raise(this, new TaskmanagerEventArgs() { Task = value }); value.Run(); } catch (Exception ex) { exception = ex; Log.Error(ex.ToString()); TaskEntry s; QueuedTasks.TryRemove(value.UniqueId, out s); s.State = "error"; s.Message = ex.ToString() + "\n " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(); s.UniqueId = value.UniqueId; s.Description = value.TaskDescription; ; s.Name = value.Name; s.TimeStamp = value.TimeStamp; ProcessedTasks.TryAdd(s.UniqueId, s); ITask irt; CurrentTasks.TryRemove(s.UniqueId, out irt); } finally { var ea = new TaskmanagerEventArgs() { Task = value, Exception = exception }; EndingTask.Raise(this, ea); TaskEntry s; QueuedTasks.TryRemove(value.UniqueId, out s); s.State = "completed"; s.Message = "Completed on: " + DateTime.Now.ToString(); s.UniqueId = value.UniqueId; s.Name = value.Name; s.Description = value.TaskDescription; s.TimeStamp = value.TimeStamp; ProcessedTasks.TryAdd(s.UniqueId, s); ITask irt; CurrentTasks.TryRemove(s.UniqueId, out irt); if (exception == null) value.End(); EndedTask.Raise(this, ea); value.Dispose(); } } else { TaskEntry s; QueuedTasks.TryRemove(value.UniqueId, out s); ProcessedTasks.TryAdd(s.UniqueId, s); value.Cancel(); } } }
private async Task ExecuteTaskAsync(TaskInfo taskInfo, CancellationToken cancellationToken) { EnsureArg.IsNotNull(taskInfo, nameof(taskInfo)); using ITask task = _taskFactory.Create(taskInfo); task.RunId = task.RunId ?? taskInfo.RunId; if (task == null) { _logger.LogWarning("Not supported task type: {taskTypeId}", taskInfo.TaskTypeId); return; } TaskResultData result = null; try { try { if (taskInfo.IsCanceled) { // For cancelled task, try to execute it for potential cleanup. task.Cancel(); } Task <TaskResultData> runningTask = Task.Run(() => task.ExecuteAsync()); _activeTaskRecordsForKeepAlive[taskInfo.TaskId] = task; result = await runningTask; } catch (RetriableTaskException ex) { _logger.LogError(ex, "Task {taskId} failed with retriable exception.", taskInfo.TaskId); try { await _consumer.ResetAsync(taskInfo.TaskId, new TaskResultData(TaskResult.Fail, ex.Message), taskInfo.RunId, cancellationToken); } catch (Exception resetEx) { _logger.LogError(resetEx, "Task {taskId} failed to reset.", taskInfo.TaskId); } // Not complete the task for retriable exception. return; } catch (Exception ex) { _logger.LogError(ex, "Task {taskId} failed.", taskInfo.TaskId); result = new TaskResultData(TaskResult.Fail, ex.Message); } try { await _consumer.CompleteAsync(taskInfo.TaskId, result, task.RunId, cancellationToken); _logger.LogInformation("Task {taskId} completed.", taskInfo.TaskId); } catch (Exception completeEx) { _logger.LogError(completeEx, "Task {taskId} failed to complete.", taskInfo.TaskId); } } finally { _activeTaskRecordsForKeepAlive.Remove(taskInfo.TaskId, out _); } }
public void Cancel() { task.Cancel(); }
/// <summary> /// Cancels selected task. /// </summary> public void Cancel(ITask task, object reason) { if (task == null) throw new ArgumentNullException("task"); task.Cancel(reason); RemoveTask(task); }
protected override void OnUnload() { _updateTask?.Cancel(); }