/// <summary>
 /// Setup thread pool to for calling receptors to process semantic types.
 /// Why do we use our own thread pool?  Because .NET's implementation (and
 /// particularly Task) is crippled and non-functional for long running threads.
 /// </summary>
 protected void InitializePoolThreads()
 {
     for (int i = 0; i < MAX_WORKER_THREADS; i++)
     {
         Thread thread = new Thread(new ParameterizedThreadStart(ProcessPoolItem));
         thread.IsBackground = true;
         ThreadSemaphore <ProcessCall> ts = new ThreadSemaphore <ProcessCall>();
         threadPool.Add(ts);
         thread.Start(ts);
     }
 }
        /// <summary>
        /// Invoke the action that we want to run on a thread.
        /// </summary>
        protected void ProcessPoolItem(object state)
        {
            ThreadSemaphore <ProcessCall> ts = (ThreadSemaphore <ProcessCall>)state;

            while (true)
            {
                ts.WaitOne();
                ProcessCall rc;

                if (ts.TryDequeue(out rc))
                {
                    Call(rc);
                }
            }
        }