HikariThreading.ThreadManager.DespawnThreadIfNeeded C# (CSharp) Method

DespawnThreadIfNeeded() private method

Checks if our situation calls for a thread to be despawned. If so, despawns one.
private DespawnThreadIfNeeded ( ) : bool
return bool
        internal bool DespawnThreadIfNeeded( )
        {
            // No going under the minimum
            if ( numThreads <= minThreads )
                return false;

            // If the boredom time is long enough, despawn and reset it.
            if ( DateTime.Now - lastNoBoredThreads > maxBoredomTimeBeforeThreadDespawn )
            {
                DespawnThread();
                lastNoBoredThreads = DateTime.Now;
                return true;
            }

            return false;
        }

Usage Example

示例#1
0
        public void DoesNotGoBelowMinimumThreads( )
        {
            ThreadManager tm = new ThreadManager(1, 100, TimeSpan.MaxValue, TimeSpan.MaxValue, 100, TimeSpan.FromMilliseconds(100));
            System.Threading.Thread.Sleep(200);
            Assert.AreEqual(1, tm.NumThreads, "Spawned more than the minimum threads?");
            bool result = tm.DespawnThreadIfNeeded();
            Assert.IsFalse(result, "Reported that it despawned a thread when at minimum.");
            Assert.AreEqual(1, tm.NumThreads, "Despawned a thread to get below minimum.");

            tm = new ThreadManager(5, 100, TimeSpan.MaxValue, TimeSpan.MaxValue, 100, TimeSpan.FromMilliseconds(100));
            System.Threading.Thread.Sleep(200);
            Assert.AreEqual(5, tm.NumThreads, "Spawned more than the minimum threads?");
            result = tm.DespawnThreadIfNeeded();
            Assert.IsFalse(result, "Reported that it despawned a thread when at minimum.");
            Assert.AreEqual(5, tm.NumThreads, "Despawned a thread to get below minimum.");
        }
All Usage Examples Of HikariThreading.ThreadManager::DespawnThreadIfNeeded