mirror of https://github.com/2dust/v2rayN
Update V2rayHandler.cs
parent
6a0bfc43dd
commit
97d7229974
|
@ -23,7 +23,8 @@ namespace v2rayN.Handler
|
|||
private static string v2rayConfigRes = Global.v2rayConfigFileName;
|
||||
private List<string> lstV2ray;
|
||||
public event ProcessDelegate ProcessEvent;
|
||||
private int processId = 0;
|
||||
//private int processId = 0;
|
||||
private Process _process;
|
||||
|
||||
public V2rayHandler()
|
||||
{
|
||||
|
@ -90,27 +91,49 @@ namespace v2rayN.Handler
|
|||
{
|
||||
try
|
||||
{
|
||||
bool blExist = true;
|
||||
if (processId > 0)
|
||||
if (_process != null)
|
||||
{
|
||||
Process p1 = Process.GetProcessById(processId);
|
||||
if (p1 != null)
|
||||
{
|
||||
p1.Kill();
|
||||
blExist = false;
|
||||
}
|
||||
KillProcess(_process);
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
}
|
||||
if (blExist)
|
||||
else
|
||||
{
|
||||
foreach (string vName in lstV2ray)
|
||||
{
|
||||
Process[] killPro = Process.GetProcessesByName(vName);
|
||||
foreach (Process p in killPro)
|
||||
Process[] existing = Process.GetProcessesByName(vName);
|
||||
foreach (Process p in existing)
|
||||
{
|
||||
p.Kill();
|
||||
var path = p.MainModule.FileName;
|
||||
if (path == $"{Utils.GetPath(vName)}.exe")
|
||||
{
|
||||
KillProcess(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//bool blExist = true;
|
||||
//if (processId > 0)
|
||||
//{
|
||||
// Process p1 = Process.GetProcessById(processId);
|
||||
// if (p1 != null)
|
||||
// {
|
||||
// p1.Kill();
|
||||
// blExist = false;
|
||||
// }
|
||||
//}
|
||||
//if (blExist)
|
||||
//{
|
||||
// foreach (string vName in lstV2ray)
|
||||
// {
|
||||
// Process[] killPro = Process.GetProcessesByName(vName);
|
||||
// foreach (Process p in killPro)
|
||||
// {
|
||||
// p.Kill();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -163,7 +186,8 @@ namespace v2rayN.Handler
|
|||
});
|
||||
p.Start();
|
||||
p.BeginOutputReadLine();
|
||||
processId = p.Id;
|
||||
//processId = p.Id;
|
||||
_process = p;
|
||||
|
||||
Global.processJob.AddProcess(p.Handle);
|
||||
}
|
||||
|
@ -187,5 +211,23 @@ namespace v2rayN.Handler
|
|||
ProcessEvent(notify, msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void KillProcess(Process p)
|
||||
{
|
||||
try
|
||||
{
|
||||
p.CloseMainWindow();
|
||||
p.WaitForExit(100);
|
||||
if (!p.HasExited)
|
||||
{
|
||||
p.Kill();
|
||||
p.WaitForExit();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue