Esempio n. 1
0
 /// <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);
     }
 }
Esempio n. 2
0
 /// <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;
         // threads.Add(thread);        // Place in list so garbage collector doesn't eventually attempt to collect a stack-created thread, as the list will have a reference to the thread.
         ThreadSemaphore <ProcessCall> ts = new ThreadSemaphore <ProcessCall>();
         threadPool.Add(ts);
         thread.Start(ts);
     }
 }
Esempio n. 3
0
        /// <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);
                }
            }
        }
Esempio n. 4
0
        /// <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 (!stopThreads)
            {
                ts.WaitOne(100);
                ProcessCall rc;

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

                    // TODO: As absurd as this is, we're trying to isolate a problem where the
                    // threads stop processing their work!
                    // Task.Run(() =>
                    {
                        try
                        {
                            rc.MakeCall();
                        }
                        catch (Exception ex)
                        {
                            Exception ex2 = ex;
                            // Prevent recursion if the exception process itself throws an exception.
                            if (!(rc.SemanticInstance is ST_Exception))
                            {
                                try
                                {
                                    ProcessInstance(Logger, new ST_Exception(ex), true);
                                }
                                catch { }
                            }
                        }
                    }// );
                }
            }
        }