/// <summary>
 /// Start our worker threads.
 /// </summary>
 protected void StartThreads()
 {
     for (int i = 0; i < MAX_WORKER_THREADS; i++)
     {
         Thread thread = new Thread(new ParameterizedThreadStart(ProcessThread));
         thread.IsBackground = true;
         ThreadSemaphore ts = new ThreadSemaphore();
         threadPool.Add(ts);
         thread.Start(ts);
     }
 }
        /// <summary>
        /// As a thread, we wait until there's something to do.
        /// </summary>
        protected void ProcessThread(object state)
        {
            ThreadSemaphore ts = (ThreadSemaphore)state;

            while (true)
            {
                ts.WaitOne();
                HttpListenerContext context;

                if (ts.TryDequeue(out context))
                {
                    Program.TimeStamp("Processing on thread " + Thread.CurrentThread.ManagedThreadId);
                    CommonResponse(context);
                }
            }
        }