private void Pendulum(object state) { if (!Monitor.TryEnter(this)) // instead of lock (this) { return; // we are exiting, because the lock is already acquired (this is not the problem because it will be soon launched again by the Timer) } try { if (stopwatch.Elapsed > m_deadline) { MaxDelayMessage("Pendulum"); stopwatch.Reset(); string message = String.Format(Resources.RestartMessageFormat, m_ObjectName, MethodCallMessageToString(m_lastCall)); AssemblyTraceEvent.Trace(TraceEventType.Critical, 162, "WatchdogProperty", message); #if DEBUG MarkRestart(message); //NUnit.Framework.Assert.Fail //( "I am about to reboot the system, but reboot is now switched off because of debug mode", "Processes.MonitoredThread" ); #else CAS.Lib.RTLib.Processes.Manager.ForceReboot(); #endif } } finally { Monitor.Exit(this); } }
private void MaxDelayMessage(string SourceName) { if (stopwatch.Elapsed > m_maxDelay) { m_maxDelay = stopwatch.Elapsed; string message = String.Format(Resources.MaxDelayMessageFormat, m_maxDelay.TotalMilliseconds.ToString(), m_ObjectName, SourceName + ":" + MethodCallMessageToString(m_lastCall)); AssemblyTraceEvent.Trace(TraceEventType.Information, 267, "WatchdogProperty", message); } }
/// <summary> /// Enters the guarded by the watchdog object. /// </summary> /// <param name="lastCall">The call message.</param> public void EnterWatchdog(IMethodCallMessage lastCall) { lock (this) { if (stopwatch.Elapsed > TimeSpan.Zero) { string message = String.Format(Resources.WatchdogStopwatchIsNotZeroMessageFormat, stopwatch.Elapsed.Milliseconds); AssemblyTraceEvent.Trace(TraceEventType.Warning, 286, "WatchdogProperty", message); } if (InsideWatchdogCoutner != 0) { string message = String.Format(Resources.InsideWatchdogMessageFormat, InsideWatchdogCoutner); AssemblyTraceEvent.Trace(TraceEventType.Warning, 291, "WatchdogProperty", message); } #if DEBUG string meth = MethodCallMessageToString(lastCall); #endif m_lastCall = lastCall; stopwatch.Start(); InsideWatchdogCoutner++; } }