Beispiel #1
0
        public static void Beat(int maxTimeToNextBeat)
        {
            if (_heartbeatDetectorEnabled == false)
            {
                return;
            }

            CheckHeartbeatThreadExists();
            HeartbeatDetector detector = GetDetector();

            lock (detector)
            {
                double currTime = Time.GetTime();

                if (detector._overdueLogged)
                {
                    int overdue = (int)detector.GetOverdue(currTime);
                    Log.MainLog.WriteDebug("Thread " + detector._thread.ManagedThreadId + " (" + detector._thread.Name + ") heartbeat overdue by " + overdue.ToString() + "ms.");
                    Log.MainLog.WriteDebug(detector._overdueStackTrace + Environment.NewLine + Environment.NewLine);
                }

                detector._lastBeatTime      = currTime;
                detector._maxTimeToNextBeat = maxTimeToNextBeat;
                detector._overdueLogged     = false;
                detector._suspended         = false;
            }
        }
Beispiel #2
0
        public static void Suspend()
        {
            if (_heartbeatDetectorEnabled == false)
            {
                return;
            }

            CheckHeartbeatThreadExists();
            HeartbeatDetector detector = GetDetector();

            lock (detector)
            {
                detector._suspended = true;
            }
        }
Beispiel #3
0
        public static void Resume()
        {
            if (_heartbeatDetectorEnabled == false)
            {
                return;
            }

            CheckHeartbeatThreadExists();
            HeartbeatDetector detector = GetDetector();

            lock (detector)
            {
                detector._lastBeatTime = Time.GetTime();
                detector._suspended    = false;
            }
        }
Beispiel #4
0
        public static void Close()
        {
            int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;

            lock (_detectors)
            {
                if (_detectors.ContainsKey(threadId))
                {
                    HeartbeatDetector detector = null;
                    detector = _detectors[threadId];
                    lock (detector)
                    {
                        _detectors.Remove(threadId);
                    }
                }
            }
        }
Beispiel #5
0
        private static HeartbeatDetector GetDetector()
        {
            HeartbeatDetector detector = null;
            int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;

            lock (_detectors)
            {
                if (_detectors.ContainsKey(threadId))
                {
                    detector = _detectors[threadId];
                }
                else
                {
                    detector = new HeartbeatDetector();
                    _detectors.Add(threadId, detector);
                }
            }
            return(detector);
        }