Ejemplo n.º 1
0
        /// <summary>
        /// Close all the threads and close the completion port if owned by Task Scheduler
        /// </summary>
        public void Dispose()
        {
            if (!m_disposed)
            {
                m_disposed = false;
                m_cancellationTokenSource.Cancel();

                for (int i = 0; i < m_numAvailableThreads; i++)
                {
                    m_completionPort.NotifyOnce();
                }

                Task.WaitAll(m_workerTasks.ToArray());

                if (m_ownCompletionPort)
                {
                    m_completionPort.Dispose();
                }

                GC.SuppressFinalize(this);
            }
        }