public void Listen(string cachedir)
{
Environment.CurrentDirectory = cdto;
Logging.Emit("creating direct cache server..");
cache = new DirectCompilerCacheServer(cachedir);
Logging.Emit("starting server threads..");
while (serverThreads.Count < MaxServerThreads)
{
NewServerThread(cachedir);
}
// maintain the threadpool
while (!quitnow)
{
foreach (var t in serverThreads.ToArray())
{
if (busyThreads > 0)
{
Logging.Emit("{0} busy threads", busyThreads);
}
if (t.Join(1000))
{
serverThreads.Remove(t);
Logging.Emit("replacing thread");
NewServerThread(cachedir);
}
}
if (busyThreads < 1)
{
Logging.Emit("server is idle..");
}
if (DateTime.Now.Subtract(lastRequest).TotalMinutes > QuitAfterIdleMinutes)
{
quitnow = true;
}
}
Logging.Emit("waiting for threads to finish");
foreach (var t in serverThreads)
{
Logging.Emit("joining thread {0}", t.ManagedThreadId);
if (!t.Join(2000))
{
Logging.Emit("thread still running..");
}
}
Logging.Emit("commiting stats");
cache.SetupStats();
Logging.Emit("server quitting");
serverMutex.ReleaseMutex();
}