コード例 #1
0
    private bool killThreadIfNeeded()
    {
        if (poolSize < threads.Count)
        {
            lock (threads)
            {
                if (poolSize < threads.Count)
                {
                    WatchableThread wt = null;
                    foreach (var tc in threads)
                    {
                        if (tc.Thread == Thread.CurrentThread)
                        {
                            wt = tc;
                        }
                    }
                    if (wt != null)
                    {
                        threads.Remove(wt);
                    }
                    return(true);
                }
            }
        }

        return(false);
    }
コード例 #2
0
 private void spawnThreads()
 {
     while (threads.Count < poolSize)
     {
         WatchableThread t = new WatchableThread(this);
         threads.Add(t);
     }
 }