我正在使用C#.NET 4和MSSQL。
该代码使用WebRequest下载不同网站的html。 代码是多线程的。
我想限制预定义域名列表中每分钟的请求数。
例如
域名:www.domain1.com每分钟请求数:5
域名:www.domain2.com每分钟请求数:20
我看到了一些建议实施“漏桶”的问题/主题。我只是不确定该怎么做。
THX!
答案 0 :(得分: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
{
...
}
}
我认为这应该指向正确的方向。