public void Execute(int amount, int time, IDbBuffer<Responses> buffer) { int sleeptime = (time * 1000) / amount; ThreadPool.SetMaxThreads(1000, 1000); ThreadPool.SetMinThreads(950, 990); var pr = DateTime.Now; for (int i = 1; i <= amount; i++) { var ipr = DateTime.Now; ThreadPool.QueueUserWorkItem(delegate { Services.ProgramManager.StartResponse(i, url, buffer); }); Thread.Sleep(sleeptime); } while (responsesGotten != amount) { } }
private static void StartResponse(int i, URLs url, IDbBuffer<Responses> buffer) { IRequests request = new Requests(url.url); string response = request.SendRequests(); var map = new StringCruncher(response); map.CrunchString(); Responses responseEntitie = new Responses(); responseEntitie.ResponseCode = map.code; responseEntitie.ResponseTime = map.timeTaken; responseEntitie.RequestStartTime = map.pr; responseEntitie.URL = url; lock (buffer) { buffer.AddToBuffer(responseEntitie); } responsesGotten++; }