尝试修复退出错误

修复停止时进程堵塞
This commit is contained in:
ChsBuffer
2020-07-25 04:02:01 +08:00
parent 6174e78696
commit bbf9c5ed7c
11 changed files with 160 additions and 151 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
using Netch.Models;
@@ -30,7 +31,8 @@ namespace Netch.Controllers
/// <returns>是否启动成功</returns>
public override bool Start(Server server, Mode mode)
{
RecordPrevious();
Task.Run(RecordPrevious);
try
{
if (server.Type == "Socks5")
@@ -79,21 +81,20 @@ namespace Netch.Controllers
/// </summary>
public override void Stop()
{
try
var tasks = new[]
{
pPrivoxyController.Stop();
NativeMethods.SetGlobal(prevHTTP, prevBypass);
if (prevPAC != "")
NativeMethods.SetURL(prevPAC);
if (!prevEnabled)
NativeMethods.SetDIRECT();
prevEnabled = false;
}
catch (Exception e)
{
Logging.Error("停止HTTP控制器错误\n" + e);
}
Task.Factory.StartNew(pPrivoxyController.Stop),
Task.Factory.StartNew(() =>
{
NativeMethods.SetGlobal(prevHTTP, prevBypass);
if (prevPAC != "")
NativeMethods.SetURL(prevPAC);
if (!prevEnabled)
NativeMethods.SetDIRECT();
prevEnabled = false;
})
};
Task.WaitAll(tasks);
}
}
}