public void AddTask(AcaciaTask task) { Interlocked.Increment(ref Statistics.StartedTasks); Tracer?.OnTaskAdding(task); EnqueueTask(task); Tracer?.OnTaskAdded(task); }
private void Worker() { while (!_tasks.IsCompleted) { AcaciaTask task = _tasks.Take(); PerformTask(task); } }
public static void Task(AcaciaTask task, bool synchronous = false) { if (synchronous) { task.Execute(); } else { Executor.AddTask(task); } }
protected void PerformTask(AcaciaTask task) { try { task.Execute(); } finally { Interlocked.Increment(ref Statistics.FinishedTasks); } }
/// <summary> /// Adds a task to be executed. /// </summary> /// <param name="name">The name, for debugging and logging.</param> /// <param name="action">The action to execute</param> override protected void EnqueueTask(AcaciaTask task) { if (_init == InitState.Uninitialised) { _init = InitState.InitialisedIdle; // Set up the idle handler Application.Idle += IdleHandler; } // Enqueue the task _tasks.Enqueue(task); }
/// <summary> /// Checks if any tasks can be executed and executes them if possible. /// </summary> private void PollTasks() { if (_tasks.Count > 0) { Stopwatch timer = new Stopwatch(); timer.Start(); do { AcaciaTask task = _tasks.Dequeue(); Logger.Instance.Trace(task.Id, "Beginning task"); PerformTask(task); Logger.Instance.Info(task.Id, "Ending task: {0}ms", timer.ElapsedMilliseconds); // Execute another task if available and we haven't taken too long. } while (_tasks.Count > 0 && timer.ElapsedMilliseconds < 50); } }
public static void Task(AcaciaTask task, bool synchronous = false) { task.TaskId = Interlocked.Increment(ref _taskId); Logger.Instance.Trace(typeof(Tasks), "TASK added: {0}", task); if (synchronous) { Logger.Instance.Trace(typeof(Tasks), "TASK exec synchronous 1: {0}", task); task.Execute(); Logger.Instance.Trace(typeof(Tasks), "TASK exec synchronous 2: {0}", task); } else { Executor.AddTask(task); } }
protected void PerformTask(AcaciaTask task) { try { Tracer?.OnTaskExecuting(task); task.Execute(); } catch (Exception e) { Tracer?.OnTaskFailed(task, e); throw e; } finally { Tracer?.OnTaskExecuted(task); Interlocked.Increment(ref Statistics.FinishedTasks); } }
private void Worker() { try { while (!_tasks.IsCompleted) { Logger.Instance.Trace(this, "Take task 1"); AcaciaTask task = _tasks.Take(); Logger.Instance.Trace(this, "Take task 2: {0}", task); PerformTask(task); Logger.Instance.Trace(this, "Take task 3: {0}", task); } Logger.Instance.Debug(this, "Worker completed"); } catch (Exception e) { Logger.Instance.Warning(this, "Worker failure: {0}", e); } }
protected override void EnqueueTask(AcaciaTask task) { Logger.Instance.Trace(this, "EnqueueTask 1: {0}", task); _tasks.Add(task); Logger.Instance.Trace(this, "EnqueueTask 2: {0}", task); }
internal void OnTaskAdded(AcaciaTask task) { GetTaskInfo(task)?.Event(TaskInfo.EventType.Added); }
protected override void EnqueueTask(AcaciaTask task) { PerformTask(task); }
public void AddTask(AcaciaTask task) { Interlocked.Increment(ref Statistics.StartedTasks); EnqueueTask(task); }
abstract protected void EnqueueTask(AcaciaTask task);
internal void OnTaskFailed(AcaciaTask task, Exception e) { GetTaskInfo(task)?.SetFailed(e); }
internal void OnTaskExecuting(AcaciaTask task) { GetTaskInfo(task)?.Event(TaskInfo.EventType.Started); }
internal void OnTaskExecuted(AcaciaTask task) { GetTaskInfo(task)?.Event(TaskInfo.EventType.Finished); }
public TaskInfo(AcaciaTask task) { this._task = task; }
protected override void EnqueueTask(AcaciaTask task) { _tasks.Add(task); }
private TaskInfo GetTaskInfo(AcaciaTask task) { return(_all.GetOrAdd(task.TaskId, new TaskInfo(task))); }
internal void OnTaskAdding(AcaciaTask task) { GetTaskInfo(task)?.Event(TaskInfo.EventType.Created); }