Example #1
0
        /// <summary>Used internally. If overridden, call parent's method first </summary>
        public virtual void  stopInternal()
        {
            if (up_queue != null)
            {
                up_queue.close(false); // this should terminate up_handler thread
            }
            if (up_handler != null && up_handler.IsAlive)
            {
                try
                {
                    up_handler.Join(THREAD_JOIN_TIMEOUT);
                }
                catch (System.Exception e)
                {
                    stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message);
                }
                if (up_handler != null && up_handler.IsAlive)
                {
                    up_handler.Interrupt();                     // still alive ? let's just kill it without mercy...
                    try
                    {
                        up_handler.Join(THREAD_JOIN_TIMEOUT);
                    }
                    catch (System.Exception e)
                    {
                        stack.NCacheLog.Error("Protocol.stopInternal()", "up_handler.Join " + e.Message);
                    }
                    if (up_handler != null && up_handler.IsAlive)
                    {
                        stack.NCacheLog.Error("Protocol", "up_handler thread for " + Name + " was interrupted (in order to be terminated), but is still alive");
                    }
                }
            }
            up_handler = null;

            if (down_queue != null)
            {
                down_queue.close(false); // this should terminate down_handler thread
            }
            if (down_handler != null && down_handler.IsAlive)
            {
                try
                {
                    down_handler.Join(THREAD_JOIN_TIMEOUT);
                }
                catch (System.Exception e)
                {
                    stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message);
                }
                if (down_handler != null && down_handler.IsAlive)
                {
                    down_handler.Interrupt();                     // still alive ? let's just kill it without mercy...
                    try
                    {
                        down_handler.Join(THREAD_JOIN_TIMEOUT);
                    }
                    catch (System.Exception e)
                    {
                        stack.NCacheLog.Error("Protocol.stopInternal()", "down_handler.Join " + e.Message);
                    }
                    if (down_handler != null && down_handler.IsAlive)
                    {
                        stack.NCacheLog.Error("Protocol", "down_handler thread for " + Name + " was interrupted (in order to be terminated), but is is still alive");
                    }
                }
            }
            down_handler = null;
        }