/// <summary> /// The main-thread of NoIIS where all client requests are arrives. /// </summary> public static void runner() { // Set the min. number of threads for the thread-pool: ThreadPool.SetMinThreads(1000, 600); // Start maintaining: Task.Factory.StartNew(() => NoIISServer.maintenanceThread(), TaskCreationOptions.LongRunning); // The HTTP listener: var listener = new HttpListener(); // Add all hosts to the listener as end-points: NoIISServer.hosts.ToList().ForEach((n) => { listener.Prefixes.Add(n); Console.WriteLine(n); }); // Start listening: listener.Start(); // Loop forever: while (true) { try { // Force a maximum number of concurrent clients: NoIISServer.semaphoreClients.Wait(); // Start the new client thread: Task.Factory.StartNew(() => NoIISServer.clientThread(listener)); } catch (Exception e) { Console.WriteLine("There was an error for starting a client thread: " + e.Message); Console.WriteLine(e.StackTrace); NoIISServer.semaphoreClients.Release(); } } }