//static SemaphoreSlim _semaphore = new SemaphoreSlim(100);
public static async Task<Stopwatch> TestAsync()
{
var server = new HttpListener();
server.Prefixes.Add($"http://{Constants.IpAddress}:{Constants.HttpPort}/");
server.Start();
Console.WriteLine("HTTP-сервер готов.");
var stopwatch = new Stopwatch();
var contexts = new List<HttpListenerContext>();
var firstGetContextTask =server.GetContextAsync();
contexts.Add(await firstGetContextTask);
Console.WriteLine("Начался HTTP-тест.");
stopwatch.Start();
var getContextOtherTasks = Enumerable
.Repeat((byte)0, Constants.ClientCount - 1)
.Select(_ =>
{
//_semaphore.Wait();
var contextTask = server.GetContextAsync();
//_semaphore.Release();
return contextTask;
});
var getContextTasks = new HashSet<Task<HttpListenerContext>>
(getContextOtherTasks)
{
firstGetContextTask
};
await ProcessAllAsync(getContextTasks);
stopwatch.Stop();
server.Stop();
return stopwatch;
}