public void OnTaskEnded(TaskDefinition task, TaskResult result, TimeSpan duration) { TaskEnded?.Invoke(new TaskEndedEvent { Task = task, Result = result, Duration = duration, Timestamp = DateTimeUtils.Now }); }
public async Task Run(CancellationToken token) { try { await RunCore(token).ConfigureAwait(false); } finally { TaskEnded?.Invoke(); } }
public RepetitiveTask(Action action, int dueTime, int period) { State = RepeririveTaskState.Stopped; DueTime = dueTime; Period = period; _action = action; TaskStarted += (task) => State = RepeririveTaskState.TaskStarted; TaskEnded += (task, status) => State = State != RepeririveTaskState.Stopped ? RepeririveTaskState.Waiting : State; _timer = new Timer((sender) => { TaskStarted?.Invoke(this); Task.Factory.StartNew(action).ContinueWith((task) => { TaskEnded?.Invoke(this, task.Status); }); }, null, Timeout.Infinite, Timeout.Infinite); }
/// <summary> /// Checks the queue for new tasks and pops the next available task /// </summary> private void PopQueue() { if (!IsEnabled) { return; } lock (_taskQueue) { Task = null; if (!_taskQueue.Any()) { return; } Task = _taskQueue[0]; _taskQueue.RemoveAt(0); } // Start a thread to execute the task _taskFactory.StartNew(() => { // Reset values IsAbortPending = false; TaskStarted?.Invoke(this, new TaskEventArgs(Task)); ResetStatus(); Logger.Record($"Executing task {Task.Type} for {Task.ModID}"); // Execute task bool result = ExecuteTask(); // Reset values ResetStatus(); Logger.Record($"Task executed {(result ? "successfully" : "unsuccessfully")}"); TaskEnded?.Invoke(this, new TaskEndedEventArgs(Task, result)); // Pop queue again PopQueue(); }); }
private void OnTaskEnded(ITaskObserver task, object sender = null) { TaskEnded?.Invoke(sender ?? this, new TaskModifiedEventArgs(task, TaskObserveStatus.Ended)); }
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { string filename = (new DirectoryInfo(savedFileName)).Name; TaskEnded?.Invoke(filename); }
private void Task_TaskEnded(object returnData) { TaskEnded?.Invoke(returnData); }