Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        protected void StartTask(WorkPartition task, bool wait)
        {
            task.Start();
            if (!ExecutingTasks.TryAdd(task.ClrTaskId, task))
            {
                Notify(ExecutionIndexUpdateFailed(task.ClrTaskId));
            }

            if (wait)
            {
                task.Wait();
            }
        }
Esempio n. 3
0
 protected WorkPartition EnqueueWork(WorkPartition workTask)
 {
     GetPartitionQueue(workTask.Partition).Enqueue(workTask);
     return(workTask);
 }