Delay 5 seconds to start controller when OS is about to resume
Workaround for slow computers Credit to GangZhou's code Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
@@ -92,7 +92,14 @@ namespace Shadowsocks
|
||||
{
|
||||
case PowerModes.Resume:
|
||||
Logging.Info("os wake up");
|
||||
_controller?.Start();
|
||||
if (_controller != null)
|
||||
{
|
||||
System.Timers.Timer timer = new System.Timers.Timer(5 * 1000);
|
||||
timer.Elapsed += Timer_Elapsed;
|
||||
timer.AutoReset = false;
|
||||
timer.Enabled = true;
|
||||
timer.Start();
|
||||
}
|
||||
break;
|
||||
case PowerModes.Suspend:
|
||||
_controller?.Stop();
|
||||
@@ -101,6 +108,32 @@ namespace Shadowsocks
|
||||
}
|
||||
}
|
||||
|
||||
private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_controller?.Start();
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (_controller != null)
|
||||
|
||||
Reference in New Issue
Block a user