private static void PerformanceWatching(int maxWaitTime, int poolingTime, string url) { double dt; //Текущее время ответа double avtime; //Среднее время ответа DateTime startRequestTime; //Время начала запроса while (true) { startRequestTime = DateTime.Now; try { WebRequest request = WebRequest.Create(url); request.Timeout = maxWaitTime; request.GetResponse(); } catch (WebException) { } catch (Exception e) { using (var evlog = new EventLogWrapper()) { evlog.WriteLog("An error was occured on aplication server starting", EventLogEntryType.Error, e); } } finally { dt = (DateTime.Now - startRequestTime).TotalMilliseconds; commonQueueRequestTime += dt; countOfQueueRequests++; avtime = commonQueueRequestTime / countOfQueueRequests; IsHighLoad = avtime > maxWaitTime || avtime > avtime * 2; if (countOfQueueRequests > counterLimit) //Фактически, учитываем только counterLimit последних запросов { commonQueueRequestTime = avtime; countOfQueueRequests = 1; } Console.WriteLine($"time={(int)dt}, avr={(int)avtime}"); Thread.Sleep(poolingTime); } } }