From c24714e1687658cc503b77b1ecd75795d74caf27 Mon Sep 17 00:00:00 2001 From: celeron533 Date: Sun, 3 Dec 2017 21:04:21 +0800 Subject: [PATCH] Simplify SystemEvents_PowerModeChanged() --- shadowsocks-csharp/Program.cs | 48 ++++++++++------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index eadbe34..50f56d2 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -122,11 +122,19 @@ namespace Shadowsocks Logging.Info("os wake up"); if (MainController != null) { - System.Timers.Timer timer = new System.Timers.Timer(10 * 1000); - timer.Elapsed += Timer_Elapsed; - timer.AutoReset = false; - timer.Enabled = true; - timer.Start(); + System.Threading.Tasks.Task.Factory.StartNew(() => + { + Thread.Sleep(10 * 1000); + try + { + MainController.Start(); + Logging.Info("controller started"); + } + catch (Exception ex) + { + Logging.LogUsefulException(ex); + } + }); } break; case PowerModes.Suspend: @@ -140,36 +148,6 @@ namespace Shadowsocks } } - private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) - { - try - { - if (MainController != null) - { - MainController.Start(); - Logging.Info("controller started"); - } - } - catch (Exception ex) - { - Logging.LogUsefulException(ex); - } - finally - { - try - { - System.Timers.Timer timer = (System.Timers.Timer)sender; - timer.Enabled = false; - timer.Stop(); - timer.Dispose(); - } - catch (Exception ex) - { - Logging.LogUsefulException(ex); - } - } - } - private static void Application_ApplicationExit(object sender, EventArgs e) { // detach static event handlers