Browse Source

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>
tags/3.3.5
Syrone Wong 8 years ago
parent
commit
f06f6f2fbb
1 changed files with 12 additions and 3 deletions
  1. +12
    -3
      shadowsocks-csharp/Program.cs

+ 12
- 3
shadowsocks-csharp/Program.cs View File

@@ -107,7 +107,7 @@ namespace Shadowsocks
Logging.Info("os wake up"); Logging.Info("os wake up");
if (_controller != null) 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.Elapsed += Timer_Elapsed;
timer.AutoReset = false; timer.AutoReset = false;
timer.Enabled = true; timer.Enabled = true;
@@ -115,7 +115,11 @@ namespace Shadowsocks
} }
break; break;
case PowerModes.Suspend: case PowerModes.Suspend:
_controller?.Stop();
if (_controller != null)
{
_controller.Stop();
Logging.Info("controller stopped");
}
Logging.Info("os suspend"); Logging.Info("os suspend");
break; break;
} }
@@ -125,7 +129,11 @@ namespace Shadowsocks
{ {
try try
{ {
_controller?.Start();
if (_controller != null)
{
_controller.Start();
Logging.Info("controller started");
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -149,6 +157,7 @@ namespace Shadowsocks
private static void Application_ApplicationExit(object sender, EventArgs e) private static void Application_ApplicationExit(object sender, EventArgs e)
{ {
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
HotKeys.Destroy(); HotKeys.Destroy();
if (_controller != null) if (_controller != null)
{ {


Loading…
Cancel
Save