Apache.NMS.ActiveMQ.Transport.InactivityMonitor.StopMonitorThreads C# (CSharp) Method

StopMonitorThreads() private method

private StopMonitorThreads ( ) : void
return void
        private void StopMonitorThreads()
        {
            lock(monitor)
            {
                if(monitorStarted.CompareAndSet(true, false))
                {
                    AutoResetEvent shutdownEvent = new AutoResetEvent(false);

                    // Attempt to wait for the Timer to shutdown, but don't wait
                    // forever, if they don't shutdown after two seconds, just quit.
                    this.connectionCheckTimer.Dispose(shutdownEvent);
                    if(!shutdownEvent.WaitOne(TimeSpan.FromMilliseconds(3000), false))
                    {
                        Tracer.WarnFormat("InactivityMonitor[{0}]: Timer Task didn't shutdown properly.", instanceId);
                    }

                    this.asyncTasks.RemoveTask(this.asyncWriteTask);
                    this.asyncTasks.RemoveTask(this.asyncErrorTask);

                    this.asyncTasks.Shutdown();
                    this.asyncTasks = null;
                    this.asyncWriteTask = null;
                    this.asyncErrorTask = null;
                    this.connectionCheckTimer = null;
                }
            }

            Tracer.DebugFormat("InactivityMonitor[{0}]: Stopped Monitor Threads.", instanceId);
        }