Parallel.For(0, data.Count(), new ParallelOptions { MaxDegreeOfParallelism = 1 }, (i) =>
{
using (HttpRequest req = new HttpRequest())
{
req.Get("xxx.ru?param=data[i]");
}
}
private static bool _running;
public static void Main()
{
_running = true;
ThreadPool.SetMaxThreads(5, 5);
ThreadPool.QueueUserWorkItem(ThreadProc);
while (_running)
{
Thread.Sleep(100);
}
}
static void ThreadProc(object stateInfo)
{
var start = DateTime.Now;
var proxy = GetProxy();
try
{
var id = GetNextId();
var result = proxy.Execute(id);
}
catch (Exception e)
{
_running = false;
}
var ts = DateTime.Now - start;
var delay = (int)(2 * 1000 - ts.TotalMilliseconds);
if (delay > 0)
Thread.Sleep(delay);
}