Refine power mode handling

- enlarge timeout to 10 seconds
- detach event handler before exiting
- output log if success

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
Syrone Wong
2016-10-24 08:27:49 +08:00
parent 89b7043a4e
commit f06f6f2fbb
+12 -3
View File
@@ -107,7 +107,7 @@ namespace Shadowsocks
Logging.Info("os wake up");
if (_controller != null)
{
System.Timers.Timer timer = new System.Timers.Timer(5 * 1000);
System.Timers.Timer timer = new System.Timers.Timer(10 * 1000);
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = false;
timer.Enabled = true;
@@ -115,7 +115,11 @@ namespace Shadowsocks
}
break;
case PowerModes.Suspend:
_controller?.Stop();
if (_controller != null)
{
_controller.Stop();
Logging.Info("controller stopped");
}
Logging.Info("os suspend");
break;
}
@@ -125,7 +129,11 @@ namespace Shadowsocks
{
try
{
_controller?.Start();
if (_controller != null)
{
_controller.Start();
Logging.Info("controller started");
}
}
catch (Exception ex)
{
@@ -149,6 +157,7 @@ namespace Shadowsocks
private static void Application_ApplicationExit(object sender, EventArgs e)
{
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
HotKeys.Destroy();
if (_controller != null)
{