AGENT.Contrib.Util.ThreadUtil.ActionConsumer C# (CSharp) Метод

ActionConsumer() приватный статический Метод

Main body of a threadpool thread. Indefinitely wait until an action is queued. When an action is de-queued safely execute it
private static ActionConsumer ( ) : void
Результат void
        private static void ActionConsumer()
        {
            while (true)
            {
                // wait on action pulse
                _threadSynch.WaitOne();

                ThreadStart action = null;

                // try and de-queue an action
                lock (lockObject)
                {
                    if (_threadActions.Count > 0)
                    {
                        action = _threadActions.Dequeue() as ThreadStart;
                    }
                    else
                    {
                        // the queue is empty and we are in a critical section
                        // safely reset the mutex so that everyone waits 
                        // until the next action is queued

                        _threadSynch.Reset();
                    }
                }

                // if we got an action execute it
                if (action != null)
                {
                    try
                    {
                        action();
                    }
                    catch (Exception ex)
                    {
                        Debug.Print("Unhandled error in thread pool: " + ex);
                    }
                }
            }
        }