Exemple #1
0
        public void CountableThreadPoolTest()
        {
            /*构建一个threadPool*/
            var threadPool = new CountableThreadPool();

            for (int i = 0; i <= 10; i++)
            {
                threadPool.Push((obj) =>
                {
                    Thread.Sleep(1000 * 30);
                }, "");
            }
            Thread.Sleep(1000 * 10);
            Assert.AreEqual(threadPool.ThreadAlive, 5);
            threadPool.WaitToExit();
            Assert.IsTrue(threadPool.ThreadAlive == 0);
        }
Exemple #2
0
 /// <summary>
 ///
 /// </summary>
 protected void InitComponent()
 {
     if (downloader == null)
     {
         this.downloader = new HttpClientDownloader();
     }
     if (pipelines.Count == 0)
     {
         pipelines.Add(new ConsolePipeline());
     }
     if (threadPool == null || threadPool.IsShutdown())
     {
         threadPool = new CountableThreadPool(threadNum);
     }
     if (startRequests != null)
     {
         foreach (var request in startRequests)
         {
             AddRequest(request);
         }
         startRequests.Clear();
     }
     startTime = DateTime.Now;
 }