Exemplo n.º 1
0
        /// <summary>
        /// Handles asynchronously finished Task, continues processing the queue.
        /// </summary>
        void TaskFinished(TTask task)
        {
            if (task.IsFaulted)
            {
                CompHelper.RequestFault(task.Exception, false);
                FinishProcessQueue();
                return;
            }

            if (processFinishedTask != null)
            {
                processFinishedTask(task);
            }

            ProcessQueueWithoutStart();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes the input queue of the block.
        /// </summary>
        protected override void ProcessQueue()
        {
            StartProcessQueue();

            try {
                int i = 0;
                while (CanRun(i))
                {
                    if (!processItem())
                    {
                        break;
                    }
                    i++;
                }
            } catch (Exception e) {
                CompHelper.RequestFault(e, false);
            }

            FinishProcessQueue();
        }
Exemplo n.º 3
0
        /// <summary>
        /// The part of <see cref="ProcessQueue"/> specific to asynchronous execution.
        /// Handles scheduling continuation on the Task returned by the block's action
        /// (or continuing synchrnously if possible).
        /// </summary>
        void ProcessQueueWithoutStart()
        {
            // catch is needed here, if the Task-returning delegate throws exception itself
            try {
                int i = 0;
                while (CanRun(i))
                {
                    TTask task;
                    if (!processItem(out task))
                    {
                        break;
                    }
                    if (task == null || task.IsCanceled ||
                        (task.IsCompleted && !task.IsFaulted))
                    {
                        if (processFinishedTask != null)
                        {
                            processFinishedTask(task);
                        }
                    }
                    else if (task.IsFaulted)
                    {
                        CompHelper.RequestFault(task.Exception, false);
                        break;
                    }
                    else
                    {
                        task.ContinueWith(
                            t => TaskFinished((TTask)t), Options.TaskScheduler);
                        return;
                    }
                    i++;
                }
            } catch (Exception e) {
                CompHelper.RequestFault(e, false);
            }

            FinishProcessQueue();
        }