tiny refactor

This commit is contained in:
Gang Zhuo
2016-03-04 21:07:54 +08:00
parent 0f7d39e27e
commit b3ce1c698a
@@ -47,20 +47,7 @@ namespace Shadowsocks.Controller
Process[] existingPolipo = Process.GetProcessesByName("ss_privoxy");
foreach (Process p in existingPolipo)
{
try
{
p.CloseMainWindow();
p.WaitForExit(100);
if (!p.HasExited)
{
p.Kill();
p.WaitForExit();
}
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
KillProcess(p);
}
string polipoConfig = Resources.privoxy_conf;
_runningPort = this.GetFreePort();
@@ -86,20 +73,30 @@ namespace Shadowsocks.Controller
{
if (_process != null)
{
try
{
_process.Kill();
_process.WaitForExit();
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
KillProcess(_process);
_process = null;
}
RefreshTrayArea();
}
private static void KillProcess(Process p)
{
try
{
p.CloseMainWindow();
p.WaitForExit(100);
if (!p.HasExited)
{
p.Kill();
p.WaitForExit();
}
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
}
private int GetFreePort()
{
int defaultPort = 8123;