From b309d786c588c370e2ca646f0219e6d82c7dc601 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Mon, 12 Mar 2018 16:24:20 +0100
Subject: [PATCH] Initialize CPU monitoring in service constructor.

---
 ATxService/AutoTx.cs | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/ATxService/AutoTx.cs b/ATxService/AutoTx.cs
index 69d1d62..0b71c5b 100644
--- a/ATxService/AutoTx.cs
+++ b/ATxService/AutoTx.cs
@@ -92,6 +92,26 @@ namespace ATxService
             LoadSettings();
             CreateIncomingDirectories();
 
+            try {
+                _cpu = new Cpu {
+                    Interval = 250,
+                    Limit = _config.MaxCpuUsage,
+                    Probation = 16,
+                    Enabled = true
+                };
+            }
+            catch (UnauthorizedAccessException ex) {
+                Log.Error("Not enough permissions to monitor the CPU load.\nMake sure the " +
+                          "service account is a member of the [Performance Monitor Users] " +
+                          "system group.\nError message was: {0}", ex.Message);
+                throw;
+            }
+            catch (Exception ex) {
+                Log.Error("Unexpected error initializing CPU monitoring: {0}", ex.Message);
+                throw;
+            }
+
+
             if (_config.DebugRoboSharp) {
                 Debugger.Instance.DebugMessageEvent += HandleDebugMessage;
                 Log.Debug("Enabled RoboSharp debug logging.");
@@ -386,26 +406,6 @@ namespace ATxService
                 throw;
             }
 
-            try {
-                _cpu = new Cpu {
-                    Interval = 250,
-                    Limit = 25,
-                    Probation = 16,
-                    Enabled = true
-                };
-            }
-            catch (UnauthorizedAccessException ex) {
-                Log.Error("Not enough permissions to monitor the CPU load.\nMake sure the " +
-                          "service account is a member of the [Performance Monitor Users] " +
-                          "system group.\nError message was: {0}", ex.Message);
-                throw;
-            }
-            catch (Exception ex) {
-                Log.Error("Unexpected error initializing CPU monitoring: {0}", ex.Message);
-                throw;
-            }
-
-
             // read the build timestamp from the resources:
             var buildTimestamp = Properties.Resources.BuildDate.Trim();
             var buildCommitName = Properties.Resources.BuildCommit.Trim();
-- 
GitLab