Skip to content

Commit

Permalink
Fixed small bug, where shutdown didn't have time to run until another…
Browse files Browse the repository at this point in the history
… was started.
  • Loading branch information
squid-box committed Jan 8, 2017
1 parent 5f21062 commit 68160c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion IdleStartWatchdog/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public partial class Service : ServiceBase
private const int MinutesToWaitBeforeShutdown = 10;
private ServiceStates _currentState;
private DateTime _lastTimeUserLoggedOut;
private bool _shutdownInitiated;

public Service()
{
InitializeComponent();
_currentState = ServiceStates.InitialStart;
_lastTimeUserLoggedOut = DateTime.MinValue;
_shutdownInitiated = false;

_log = new EventLog("Application", ".", "IdleStartWatchdog");
_timer = new Timer(1000) {AutoReset = true};
Expand Down Expand Up @@ -84,8 +86,13 @@ protected override void OnStop()
}
}

private static void ShutdownComputer()
private void ShutdownComputer()
{
if (_shutdownInitiated)
{
return;
}

var psi = new ProcessStartInfo()
{
FileName = "shutdown",
Expand All @@ -94,6 +101,7 @@ private static void ShutdownComputer()
UseShellExecute = false
};

_shutdownInitiated = true;
Process.Start(psi);
}

Expand Down

0 comments on commit 68160c1

Please sign in to comment.