/// <summary> /// Starts this instance. /// </summary> public void Start() { try { if (!Architecture.IsAssemblyX64 && Architecture.IsRunningX64) { throw new UnsupportedPlatformException(); } if (!Running) { this.LogInfo("Starting Device Monitor"); if (UpdateTimer != null) { UpdateTimer.Change(0, this.UpdateInterval * 1000); } else { UpdateTimer = new System.Threading.Timer(new System.Threading.TimerCallback(TimerUpdate), null, 0, this.UpdateInterval * 1000); } Running = true; } } catch (Exception ex) { this.LogError(ex.Message, ex); Running = false; } }
/// <summary> /// Stops this instance. /// </summary> public void Stop() { if (UpdateTimer != null && Running) { this.LogInfo("Stopping Device Monitor"); // unregister all connected devices and all "known" devices Devices.Union(KnownDeviceManager.Instance.GetKnownDevices()).ToList().ForEach(d => { OnDeviceStateChanged(new DeviceEventArgs(d, CommandRunner.DeviceState.Offline)); }); UpdateTimer.Change(-1, -1); Running = false; } }
private void FullRestartTimerCallback(object?parameter) { if (UpdateTimer != null) { AddLog("Restarting the timer"); // Restart the update timer from scratch. UpdateTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); UpdateTimer = new Timer(new TimerCallback(UpdateTimerCallback)); UpdateTimer.Change(TimeInterval, TimeInterval); AddLog("Timer restarted"); } else { AddLog("No timer to restart"); } FullRestartTimer?.Change(FullRestartInterval, Timeout.InfiniteTimeSpan); AddLog($"Next check scheduled at {DateTime.UtcNow + FullRestartInterval}"); }
private void StopServiceManager() { UpdateTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); }