diff --git a/Mamesaver/Power/PowerManager.cs b/Mamesaver/Power/PowerManager.cs
index 374e48b..bc62715 100644
--- a/Mamesaver/Power/PowerManager.cs
+++ b/Mamesaver/Power/PowerManager.cs
@@ -76,7 +76,7 @@ public void Initialise()
powerType.Value.ToString(), _sleepTimeout.TotalMinutes);
// Create a timer which fires once when the display or computer should go to sleep
- _sleepTimer = new Timer { Interval = (int)_sleepTimeout.TotalMilliseconds, AutoReset = false };
+ _sleepTimer = new Timer { Interval = Math.Min(_sleepTimeout.TotalMilliseconds, int.MaxValue), AutoReset = false };
_sleepTimer.Elapsed += SleepTimerTick;
_sleepTimer.Start();
@@ -125,7 +125,7 @@ private void PowerStateChanged(object sender, EventArgs args)
powerType.Value.ToString(), _sleepTimeout.TotalMinutes);
// Update sleep timer on power state change due to different sleep configurations
- _sleepTimer.Interval = (int)_sleepTimeout.TotalMilliseconds;
+ _sleepTimer.Interval = Math.Min(_sleepTimeout.TotalMilliseconds, int.MaxValue);
_sleepTimer.Stop();
_sleepTimer.Start();
diff --git a/Mamesaver/Windows/UserActivityHook.cs b/Mamesaver/Windows/UserActivityHook.cs
index dda76f1..233b6b7 100644
--- a/Mamesaver/Windows/UserActivityHook.cs
+++ b/Mamesaver/Windows/UserActivityHook.cs
@@ -479,20 +479,21 @@ public UserActivityHook(bool InstallMouseHook, bool InstallKeyboardHook)
Start(InstallMouseHook, InstallKeyboardHook);
}
- public void Dispose()
+ protected virtual void Dispose(bool disposing)
{
- //uninstall hooks and do not throw exceptions
- Stop(true, true, false);
+ if (disposing)
+ {
+ Stop(true, true, false);
+ }
}
-
- ///
- /// Destruction.
- ///
- ~UserActivityHook()
+ public void Dispose()
{
- Dispose();
+ Dispose(true);
+ GC.SuppressFinalize(this);
}
+ ~UserActivityHook() => Dispose(false);
+
///
/// Occurs when the user moves the mouse, presses any mouse button or scrolls the wheel
///