From f06f6f2fbb716c898df27e93d15b16e9def19f66 Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Mon, 24 Oct 2016 08:27:49 +0800 Subject: [PATCH] Refine power mode handling - enlarge timeout to 10 seconds - detach event handler before exiting - output log if success Signed-off-by: Syrone Wong --- shadowsocks-csharp/Program.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index 0f19adca..4630cf76 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -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) {