Пример #1
0
        public void StopAllThreads(ThreadPoolStopSettings settings)
        {
            //log.Info("Signaling all threads to stop");

            lock (threads)
            {
                foreach (IThread thread in threads)
                {
                    thread.SignalToStop();
                }

                List <IThread> remainingThreads = new List <IThread>(threads);

                for (int i = 0; remainingThreads.Count > 0 && i < settings.MaxStoppingLoops; i++)
                {
                    Thread.Sleep(i == 0 ? settings.InitialStoppingTimeout : settings.SubsequentStoppingTimeout);

                    List <IThread> threadsToProcess = new List <IThread>(remainingThreads);
                    foreach (IThread thread in threadsToProcess)
                    {
                        if (!thread.IsAlive || thread.Join(TimeSpan.Zero))
                        {
                            //if (log.IsDebugEnabled)
                            //    log.DebugFormat("Thread {0} stopped normally", thread.ManagedThreadId);

                            remainingThreads.Remove(thread);
                            thread.Dispose();
                        }
                    }
                }

                foreach (IThread thread in remainingThreads)
                {
                    //log.WarnFormat("Aborting thread {0} since it failed to stop normally", thread.ManagedThreadId);
                    thread.Abort();
                }

                threads.Clear();
            }
        }
Пример #2
0
        void IThreadPool.StopAllThreads(ThreadPoolStopSettings settings)
        {
            Contract.Requires(settings != null);

            throw new NotImplementedException();
        }