Пример #1
0
        private void StopMonitorThreads()
        {
            lock (_monitor)
                if (_monitorStarted.CompareAndSet(true, false))
                {
                    _connectionCheckTimer.Dispose();

                    _connectionCheckTimer.Dispose();

                    _asyncTasks.Shutdown();
                    _asyncTasks     = null;
                    _asyncWriteTask = null;
                    _asyncErrorTask = null;
                }
        }
Пример #2
0
        private void StopMonitorThreads()
        {
            lock (_monitor)
                if (_monitorStarted.CompareAndSet(true, false))
                {
                    // Attempt to wait for the Timer to shutdown, but don't wait
                    // forever, if they don't shutdown after two seconds, just quit.
                    ThreadUtil.DisposeTimer(_connectionCheckTimer, 2000);

                    _connectionCheckTimer.Dispose();

                    _asyncTasks.Shutdown();
                    _asyncTasks     = null;
                    _asyncWriteTask = null;
                    _asyncErrorTask = null;
                }
        }
Пример #3
0
        private void StartMonitorThreads()
        {
            lock ( _monitor )
            {
                if (IsDisposed || _disposing)
                {
                    return;
                }

                if (_monitorStarted.Value)
                {
                    return;
                }

                if (_localWireFormatInfo == null)
                {
                    return;
                }

                if (_remoteWireFormatInfo == null)
                {
                    return;
                }

                if (_localWireFormatInfo.MaxInactivityDuration != 0 &&
                    _remoteWireFormatInfo.WriteCheckInterval != 0)
                {
                    ReadCheckTime =
                        Math.Max(
                            _localWireFormatInfo.ReadCheckInterval,
                            _remoteWireFormatInfo.WriteCheckInterval);

                    _asyncErrorTask = new AsyncSignalReadErrorkTask(this, Next.RemoteAddress);
                }

                if (_localWireFormatInfo.MaxInactivityDuration != 0)
                {
                    if (_remoteWireFormatInfo.Version > 1.0)
                    {
                        WriteCheckTime =
                            Math.Max(_localWireFormatInfo.WriteCheckInterval,
                                     _remoteWireFormatInfo.ReadCheckInterval);
                    }
                    else
                    {
                        WriteCheckTime = _localWireFormatInfo.WriteCheckInterval;
                    }

                    _asyncWriteTask = new AsyncWriteTask(this);
                }

                InitialDelayTime = _localWireFormatInfo.MaxInactivityDurationInitialDelay > 0
                    ? _localWireFormatInfo.MaxInactivityDurationInitialDelay
                    : WriteCheckTime;

                _asyncTasks = new CompositeTaskRunner();

                if (_asyncErrorTask != null)
                {
                    _asyncTasks.AddTask(_asyncErrorTask);
                }

                if (_asyncWriteTask != null)
                {
                    Tracer.WarnFormat("InactivityMonitor[{0}]: Write Check time interval: {1}",
                                      _instanceId,
                                      WriteCheckTime);
                    _asyncTasks.AddTask(_asyncWriteTask);
                }

                if (_asyncErrorTask == null && _asyncWriteTask == null)
                {
                    return;
                }

                Tracer.WarnFormat("InactivityMonitor[{0}]: Starting the Monitor Timer.", _instanceId);
                _monitorStarted.Value = true;

                _connectionCheckTimer = new Timer(
                    CheckConnection,
                    null,
                    InitialDelayTime,
                    WriteCheckTime
                    );
            }
        }