Clear() public method

Clear all the work items
public Clear ( ) : void
return void
Exemplo n.º 1
0
        public override void Cancel(bool abortExecution)
        {
            lock (_lock)
            {
                _canceledWorkItemsGroup.IsCanceled = true;
                _workItemsQueue.Clear();
                _workItemsInStpQueue    = 0;
                _canceledWorkItemsGroup = new CanceledWorkItemsGroup();
            }

            if (abortExecution)
            {
                _stp.CancelAbortWorkItemsGroup(this);
            }
        }
        /// <summary>
        /// Cleanup the work items queue, hence no more work
        /// items are allowed to be queue
        /// </summary>
        protected virtual void Cleanup()
        {
            lock (this)
            {
                // Deactivate only once
                if (!_isWorkItemsQueueActive)
                {
                    return;
                }

                // Don't queue more work items
                _isWorkItemsQueueActive = false;

                foreach (WorkItem workItem in _workItems)
                {
                    workItem.DisposeOfState();
                }

                // Clear the work items that are already queued
                _workItems.Clear();

                // Note:
                // I don't iterate over the queue and dispose of work items's states,
                // since if a work item has a state object that is still in use in the
                // application then I must not dispose it.

                // Tell the waiters that they were timed out.
                // It won't signal them to exit, but to ignore their
                // next work item.
                while (_waitersCount > 0)
                {
                    WaiterEntry waiterEntry = PopWaiter();
                    waiterEntry.Timeout();
                }
            }
        }