diff --git a/ATxCommon/Monitoring/Cpu.cs b/ATxCommon/Monitoring/Cpu.cs index 02f5a8b18f4168da175e298707bf71c5b38edb86..71aeb8529149404e0a0f3be008883fac789996a9 100644 --- a/ATxCommon/Monitoring/Cpu.cs +++ b/ATxCommon/Monitoring/Cpu.cs @@ -55,6 +55,11 @@ namespace ATxCommon.Monitoring /// <returns>The average CPU load from the last four readings.</returns> public float Load { get; private set; } + /// <summary> + /// Flag representing whether the load is considered to be high or low. + /// </summary> + public bool HighLoad { get; private set; } + /// <summary> /// How often (in ms) to check the CPU load. /// </summary> @@ -116,8 +121,10 @@ namespace ATxCommon.Monitoring Log.Debug("CPU monitoring initializing PerformanceCounter (takes one second)..."); _cpuCounter.NextValue(); Thread.Sleep(1000); - Log.Debug("CPU monitoring current load: {0:0.0}", _cpuCounter.NextValue()); - // _monitoringTimer = new Timer(_interval); + var curLoad = _cpuCounter.NextValue(); + Log.Debug("CPU monitoring current load: {0:0.0}", curLoad); + // now initialize the load state: + HighLoad = curLoad > _limit; _monitoringTimer = new Timer(_interval); _monitoringTimer.Elapsed += UpdateCpuLoad; } @@ -177,6 +184,7 @@ namespace ATxCommon.Monitoring /// Raise the "LoadAboveLimit" event. /// </summary> protected virtual void OnLoadAboveLimit() { + HighLoad = true; LoadAboveLimit?.Invoke(this, EventArgs.Empty); } @@ -184,6 +192,7 @@ namespace ATxCommon.Monitoring /// Raise the "LoadBelowLimit" event. /// </summary> protected virtual void OnLoadBelowLimit() { + HighLoad = false; LoadBelowLimit?.Invoke(this, EventArgs.Empty); } }