Ejemplo n.º 1
0
 public void OnTaskEnded(TaskDefinition task, TaskResult result, TimeSpan duration)
 {
     TaskEnded?.Invoke(new TaskEndedEvent
     {
         Task      = task,
         Result    = result,
         Duration  = duration,
         Timestamp = DateTimeUtils.Now
     });
 }
Ejemplo n.º 2
0
 public async Task Run(CancellationToken token)
 {
     try
     {
         await RunCore(token).ConfigureAwait(false);
     }
     finally
     {
         TaskEnded?.Invoke();
     }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        /// <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();
            });
        }
Ejemplo n.º 5
0
 private void OnTaskEnded(ITaskObserver task, object sender = null)
 {
     TaskEnded?.Invoke(sender ?? this, new TaskModifiedEventArgs(task, TaskObserveStatus.Ended));
 }
Ejemplo n.º 6
0
        private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string filename = (new DirectoryInfo(savedFileName)).Name;

            TaskEnded?.Invoke(filename);
        }
Ejemplo n.º 7
0
 private void Task_TaskEnded(object returnData)
 {
     TaskEnded?.Invoke(returnData);
 }