/// <summary> /// Check system parameters for valid ranges and update the global service state accordingly. /// </summary> private void UpdateServiceState() { var suspendReasons = new List <string>(); // check all system parameters for valid ranges and remember the reason in a string // if one of them is failing (to report in the log why we're suspended) if (_phyDisk.HighLoad) { suspendReasons.Add("Disk I/O"); } if (_cpu.HighLoad) { suspendReasons.Add("CPU"); } if (SystemChecks.GetFreeMemory() < _config.MinAvailableMemory) { suspendReasons.Add("RAM"); } var blacklistedProcess = SystemChecks.CheckForBlacklistedProcesses( _config.BlacklistedProcesses); if (!string.IsNullOrWhiteSpace(blacklistedProcess)) { suspendReasons.Add("process '" + blacklistedProcess + "'"); } // all parameters within valid ranges, so set the state to "Running": if (suspendReasons.Count == 0) { _status.SetSuspended(false, "all parameters in valid ranges"); return; } // set state to "Running" if no-one is logged on: if (SystemChecks.NoUserIsLoggedOn()) { _status.SetSuspended(false, "no user is currently logged on"); return; } // by reaching this point we know the service should be suspended: _status.SetSuspended(true, string.Join(", ", suspendReasons)); }