2010-08-24 42 views
2

我正在使用C#.NET 4和MSSQL。.NET WebRequest Throttling

該代碼使用WebRequest下載不同網站的html。代碼是多線程的。

我想限制預先定義的域列表每個請求的數量。

例如

域:www.domain1.com要求按最低:5

域:www.domain2.com要求按最低:20

我看到了一些問題/建議實施「漏斗」的主題。我只是不知道該怎麼做。

Thx!

回答

0

你可以做這樣的事情:

while (true) 
     { 
      // read how long to wait between scans 
      // we do this here so that we could, conceivably, update this value while the scanner is running 
      int scanwaittime = int.Parse(ConfigurationManager.AppSettings["WaitTime"].ToString()); 


      if (Engine.IsRunning) 
      { 
       // engine is already running another scan - give it some more time 
       System.Threading.Thread.Sleep(scanwaittime); 
      } 
      else 
      { 
       ... 
      } 
     } 

這應該指向你在正確的方向,我想。