From 16815f4a511b7d23c62c6e5d57bb04d27f3af091 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Sun, 11 Mar 2018 16:50:02 +0100
Subject: [PATCH] Example for using the new ATxCommon.Monitoring.Cpu class.

---
 ATxService/AutoTx.cs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs
index fb941a8..bb8a9cf 100644
--- a/ATxService/AutoTx.cs
+++ b/ATxService/AutoTx.cs
@@ -8,6 +8,7 @@ using System.IO;
 using System.Reflection;
 using System.Timers;
 using ATxCommon;
+using ATxCommon.Monitoring;
 using ATxCommon.NLog;
 using ATxCommon.Serializables;
 using NLog;
@@ -46,6 +47,7 @@ namespace ATxService
         public PerformanceCounter CpuCounter;
         private float _cpuLoad;
         private readonly float[] _cpuLoadLastReadings = {0F, 0F, 0F, 0F};
+        private Cpu _cpu;
 
         private DateTime _lastUserDirCheck = DateTime.MinValue;
 
@@ -409,6 +411,8 @@ namespace ATxService
                 _loadTimer = new Timer(250);
                 _loadTimer.Elapsed += UpdateCpuLoad;
                 _loadTimer.Enabled = true;
+
+                _cpu = new Cpu();
             }
             catch (Exception ex) {
                 Log.Error("Error in OnStart(): {0}", ex.Message);
@@ -499,7 +503,7 @@ namespace ATxService
             // while this method has not finished yet:
             _mainTimer.Enabled = false;
 
-            Log.Debug("Current CPU load: {0}", _cpuLoad);
+            Log.Debug("CPU load: {0:#} / {1:#} ({2:#.##})", _cpuLoad, _cpu.Load(), _cpuLoad - _cpu.Load());
 
             try {
                 RunMainTasks();
-- 
GitLab