Esempio n. 1
0
        /// <summary>
        /// Queue's an <see cref="IExecObj"/> for execution.
        /// <seealso cref="IExecObj"/>
        /// </summary>
        /// <param name="obj">The object to be executed</param>
        /// <returns>True if the object was successfully queued.</returns>
        /// <remarks>
        /// If the <see cref="ThreadMgr"/> hasn't been started yet or has been stopped the return value will be false. Otherwise it's always true.
        /// </remarks>
        public static bool QueueExecObj(IExecObj obj)
        {
            if (m_running)
            {
                if (m_singleThread)
                {
                    m_queueSpinLock.Enter();

                    try
                    {
                        m_queue.Add(obj);
                    }
                    finally
                    {
                        m_queueSpinLock.Exit();
                    }
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(PoolMain), obj);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Asynchronously executes an execution object.
        /// <seealso cref="IExecObj"/>
        /// <seealso cref="ThreadMgr.QueueExecObj"/>
        /// </summary>
        /// <param name="state">The object to be executed.</param>
        private static void PoolMain(object state)
        {
            IExecObj obj = (IExecObj)state;

            try
            {
                obj.Execute();

                if (m_objExec != null)
                {
                    m_objExec(obj);
                }
            }
            catch (Exception e)
            {
                //LogManager.GetLogger(CellDef.CORE_LOG_FNAME).Error(e.ToString());

                Console.WriteLine("Error: " + e.ToString());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Queue's an <see cref="IExecObj"/> for execution.
        /// <seealso cref="IExecObj"/>
        /// </summary>
        /// <param name="obj">The object to be executed</param>
        /// <returns>True if the object was successfully queued.</returns>
        /// <remarks>
        /// If the <see cref="ThreadMgr"/> hasn't been started yet or has been stopped the return value will be false. Otherwise it's always true.
        /// </remarks>
        public static bool QueueExecObj(IExecObj obj)
        {
            if (m_running)
            {
                if (m_singleThread)
                {
                    m_queueSpinLock.Enter();

                    try
                    {
                        m_queue.Add(obj);
                    }
                    finally
                    {
                        m_queueSpinLock.Exit();
                    }
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(PoolMain), obj);
                }

                return true;
            }

            return false;
        }