Exemple #1
0
        protected virtual void SetStatusManager(GroupStatusManager statusManager)
        {
            CheckDisposed();

            if (statusManager == null)
            {
                throw new ArgumentNullException("statusManager");
            }
            else if (gsm != null)
            {
                throw new InvalidOperationException("StatusManager already set");
            }

            gsm = statusManager;
            gsm.StatusChanged += OnStatusChangedHandler;
        }
Exemple #2
0
        public virtual void Dispose(AutoResetEvent handle)
        {
            if (SetDisposed())
            {
                commandQueue.Dispose();

                try {
                    lock (sync) {
                        tasks.TaskAdded   -= OnTaskAddedHandler;
                        tasks.TaskRemoved -= OnTaskRemovedHandler;
                        tasks.CommandQueue = null;

                        if (tasks.Count > 0)
                        {
                            Disassociate(tasks);
                        }
                    }

                    gsm.StatusChanged -= OnStatusChangedHandler;
                    gsm.Dispose();

                    gpm.ProgressChanged -= OnProgressChangedHandler;
                    gpm.Reset();
                } finally {
                    gpm   = null;
                    gsm   = null;
                    tasks = null;
                }

                if (executingHandle != null)
                {
                    executingHandle.Close();
                    executingHandle = null;
                }

                if (execHandle != null)
                {
                    execHandle.Close();
                    execHandle = null;
                }
            }

            if (handle != null)
            {
                handle.Set();
            }
        }
Exemple #3
0
        protected TaskGroup(int maxRunningTasks,
                            TaskCollection <T> tasks,
                            GroupStatusManager statusManager,
                            GroupProgressManager <T> progressManager)
        {
            if (maxRunningTasks < 0)
            {
                throw new ArgumentException("maxRunningTasks must be >= 0");
            }
            else if (tasks == null)
            {
                throw new ArgumentNullException("tasks");
            }

            sync         = tasks.SyncRoot;
            currentTasks = new List <T> (maxRunningTasks);

            commandQueue = new AsyncCommandQueue();
            id           = CommandQueueManager.Register(commandQueue);

            SetProgressManager(
                progressManager ?? new GroupProgressManager <T> ()
                );

            SetStatusManager(
                statusManager ?? new GroupStatusManager()
                );

            try {
                gsm.SuspendUpdate = true;

                gsm.RemainingTasks  = tasks.Count;
                gsm.MaxRunningTasks = maxRunningTasks;

                SetTaskCollection(tasks);
            } finally {
                gsm.SuspendUpdate = false;
                gsm.Update();
            }
        }
Exemple #4
0
 public TaskGroup(int maxRunningTasks,
                  TaskCollection <T> tasks,
                  GroupStatusManager statusManager)
     : this(maxRunningTasks, tasks, statusManager, null)
 {
 }