コード例 #1
0
ファイル: ThreadQueue.cs プロジェクト: SmaSTra/SmaSTra
        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
ファイル: ThreadQueue.cs プロジェクト: SmaSTra/SmaSTra
        internal void ThreadDone(ThreadQueueItem thread)
        {
            try
            {
                this.threadDoneMutex.WaitOne();

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

                this.ExecuteThreads();
            }
            finally
            {
                this.threadDoneMutex.ReleaseMutex();
            }
        }
コード例 #3
0
ファイル: ThreadQueue.cs プロジェクト: SmaSTra/SmaSTra
        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
ファイル: ThreadQueue.cs プロジェクト: SmaSTra/SmaSTra
 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();
                     }
                 }
             }
         }
     }
 }