我使用的是C# .NET 4和MSSQL。
代码使用WebRequest下载不同网站的html。代码是多线程的。
我想限制每分钟对预先定义的域名列表的请求数量。
例如
域名: www.domain1.com请求每个Min : 5
域名: www.domain2.com / Min : 20
我看到了一些建议实现“漏桶”的问题/主题。我只是不知道该怎么做。
谢谢!
发布于 2011-07-01 17:27:26
你可以这样做:
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
{
...
}
}我想这应该会给你指明正确的方向。
https://stackoverflow.com/questions/3555927
复制相似问题