Browse Source

Simplify SystemEvents_PowerModeChanged()

tags/4.0.7
celeron533 7 years ago
parent
commit
c24714e168
1 changed files with 13 additions and 35 deletions
  1. +13
    -35
      shadowsocks-csharp/Program.cs

+ 13
- 35
shadowsocks-csharp/Program.cs View File

@@ -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


Loading…
Cancel
Save