/// <summary> /// Enqueues a unit of work /// </summary> /// <param name="work">The work to be performed</param> /// <param name="worker">The handler that will be invoked to perform the work</param> /// <param name="observers">A listener for which appropriate actions will be invoked during /// execution</param> /// <returns></returns> public WorkPartition Submit(IPartitionedWork work, Action <IPartitionedWork> worker, IReadOnlyList <IWorkAgentObserver> observers) { var clrTaskId = WorkPartition.AssignIdentity(); Action <IPartitionedWork> adapter = w => { iter(observers, observer => observer.RaiseWorkDispatched(work)); try { worker(work); } finally { HandleTaskCompletion(clrTaskId).OnNone(() => Notify(AppMessage.Warn("There was no task to complete"))); } iter(observers, observer => observer.RaiseWorkCompleted(work)); }; var workTask = EnqueueWork(WorkPartition.Create(clrTaskId, work, adapter)); iter(observers, observer => observer.RaiseWorkSubmitted(work)); return(workTask); }
protected void StartTask(WorkPartition task, bool wait) { task.Start(); if (!ExecutingTasks.TryAdd(task.ClrTaskId, task)) { Notify(ExecutionIndexUpdateFailed(task.ClrTaskId)); } if (wait) { task.Wait(); } }
protected WorkPartition EnqueueWork(WorkPartition workTask) { GetPartitionQueue(workTask.Partition).Enqueue(workTask); return(workTask); }