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