Skip to content

Commit

Permalink
Fix for timer interval - Fixes #29
Browse files Browse the repository at this point in the history
Also fix for dispose method on UserActivityHook throwing exception
  • Loading branch information
mika76 committed Sep 6, 2018
1 parent f47cd3b commit a795e38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Mamesaver/Power/PowerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 10 additions & 9 deletions Mamesaver/Windows/UserActivityHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/// <summary>
/// Destruction.
/// </summary>
~UserActivityHook()
public void Dispose()
{
Dispose();
Dispose(true);
GC.SuppressFinalize(this);
}

~UserActivityHook() => Dispose(false);

/// <summary>
/// Occurs when the user moves the mouse, presses any mouse button or scrolls the wheel
/// </summary>
Expand Down

0 comments on commit a795e38

Please sign in to comment.