Пример #1
0
        public void MoveToFront(ThreadQueueItem thread)
        {
            if (thread == null)
            {
                throw new ArgumentNullException("thread");
            }

            lock (this.waitingThreads)
            {
                int index = this.waitingThreads.IndexOf(thread);
                if (index > 0)
                {
                    this.waitingThreads.MoveItem(index, 0);
                }
            }
        }
Пример #2
0
        internal void ThreadDone(ThreadQueueItem thread)
        {
            try
            {
                this.threadDoneMutex.WaitOne();

                lock (this.executingThreads)
                {
                    this.executingThreads.Remove(thread);
                }

                this.ExecuteThreads();
            }
            finally
            {
                this.threadDoneMutex.ReleaseMutex();
            }
        }
Пример #3
0
        public ThreadQueueItem EnqueueThread(Action threadAction)
        {
            if (threadAction == null)
            {
                throw new ArgumentNullException("threadAction");
            }

            ThreadQueueItem newThread = new ThreadQueueItem(this, threadAction, this.threadCounter++);

            lock (this.waitingThreads)
            {
                this.waitingThreads.Add(newThread);
            }

            this.ExecuteThreads();

            return(newThread);
        }
Пример #4
0
 private void ExecuteThreads()
 {
     lock (this.waitingThreads)
     {
         lock (this.executingThreads)
         {
             while (this.executingThreads.Count < this.maxExecutingThreads && this.waitingThreads.Count != 0)
             {
                 ThreadQueueItem newThread = this.waitingThreads.First();
                 this.waitingThreads.RemoveAt(0);
                 this.executingThreads.Add(newThread);
                 if (this.executingThreads.Count >= this.minExecutingThreads)
                 {
                     foreach (var thread in this.executingThreads)
                     {
                         thread.Execute();
                     }
                 }
             }
         }
     }
 }