From e6b1e22245424bf849f4b67327693e0ac738e6f5 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:42:58 +0800 Subject: [PATCH] Update UpgradeApp.cs --- v2rayN/AmazTool/UpgradeApp.cs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/v2rayN/AmazTool/UpgradeApp.cs b/v2rayN/AmazTool/UpgradeApp.cs index 92c4b153..a6acf64b 100644 --- a/v2rayN/AmazTool/UpgradeApp.cs +++ b/v2rayN/AmazTool/UpgradeApp.cs @@ -19,18 +19,15 @@ namespace AmazTool return; } + Console.WriteLine("Try to end the process(尝试结束进程)."); try { - Process[] existing = Process.GetProcessesByName(V2rayN); - foreach (Process p in existing) - { - var path = p.MainModule?.FileName ?? ""; - if (path.StartsWith(GetPath(V2rayN))) - { - p.Kill(); - p.WaitForExit(100); - } - } + var path = GetPath(V2rayN); + Console.WriteLine(path); + var existing = Process.GetProcessesByName(V2rayN); + var pp = existing.FirstOrDefault(p => p.MainModule?.FileName != null && p.MainModule?.FileName == path); + pp?.Kill(); + pp?.WaitForExit(1000); } catch (Exception ex) { @@ -39,6 +36,7 @@ namespace AmazTool "Close it manually, or the upgrade may fail.(请手动关闭正在运行的v2rayN,否则可能升级失败。\n\n" + ex.StackTrace); } + Console.WriteLine("Start extracting files(开始解压文件)."); StringBuilder sb = new(); try { @@ -84,13 +82,12 @@ namespace AmazTool } if (sb.Length > 0) { - Console.WriteLine("Upgrade Failed.\n" + - "(升级失败)." + sb.ToString()); + Console.WriteLine("Upgrade Failed(升级失败)." + sb.ToString()); return; } Console.WriteLine("Start v2rayN, please wait...(正在重启,请等待)"); - Thread.Sleep(3000); + Thread.Sleep(9000); Process process = new() { StartInfo = new()