diff --git a/v2rayN/ServiceLib/Common/ProcUtils.cs b/v2rayN/ServiceLib/Common/ProcUtils.cs index 561278ce..2819f2fb 100644 --- a/v2rayN/ServiceLib/Common/ProcUtils.cs +++ b/v2rayN/ServiceLib/Common/ProcUtils.cs @@ -67,116 +67,4 @@ public static class ProcUtils Logging.SaveLog(_tag, ex); } } - - public static async Task ProcessKill(int pid) - { - try - { - await ProcessKill(Process.GetProcessById(pid), false); - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - } - } - - public static async Task ProcessKill(Process? proc, bool review) - { - if (proc is null) - { - return; - } - - GetProcessKeyInfo(proc, review, out var procId, out var fileName, out var processName); - - try - { - if (Utils.IsNonWindows()) - { - proc?.Kill(true); - } - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - } - - try - { - proc?.Kill(); - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - } - - try - { - proc?.Close(); - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - } - - try - { - proc?.Dispose(); - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - } - - await Task.Delay(300); - await ProcessKillByKeyInfo(review, procId, fileName, processName); - } - - private static void GetProcessKeyInfo(Process? proc, bool review, out int? procId, out string? fileName, out string? processName) - { - procId = null; - fileName = null; - processName = null; - if (!review) - { - return; - } - try - { - procId = proc?.Id; - fileName = proc?.MainModule?.FileName; - processName = proc?.ProcessName; - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - } - } - - private static async Task ProcessKillByKeyInfo(bool review, int? procId, string? fileName, string? processName) - { - if (review && procId != null && fileName != null) - { - try - { - var lstProc = Process.GetProcessesByName(processName); - foreach (var proc2 in lstProc) - { - if (proc2.Id == procId) - { - Logging.SaveLog($"{_tag}, KillProcess not completing the job, procId"); - await ProcessKill(proc2, false); - } - if (proc2.MainModule != null && proc2.MainModule?.FileName == fileName) - { - Logging.SaveLog($"{_tag}, KillProcess not completing the job, fileName"); - } - } - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - } - } - } } diff --git a/v2rayN/ServiceLib/Common/Job.cs b/v2rayN/ServiceLib/Common/WindowsJob.cs similarity index 98% rename from v2rayN/ServiceLib/Common/Job.cs rename to v2rayN/ServiceLib/Common/WindowsJob.cs index fe968d2d..f7fd2d74 100644 --- a/v2rayN/ServiceLib/Common/Job.cs +++ b/v2rayN/ServiceLib/Common/WindowsJob.cs @@ -7,11 +7,11 @@ namespace ServiceLib.Common; * http://stackoverflow.com/questions/6266820/working-example-of-createjobobject-setinformationjobobject-pinvoke-in-net */ - public sealed class Job : IDisposable + public sealed class WindowsJob : IDisposable { private IntPtr handle = IntPtr.Zero; - public Job() + public WindowsJob() { handle = CreateJobObject(IntPtr.Zero, null); var extendedInfoPtr = IntPtr.Zero; @@ -94,7 +94,7 @@ namespace ServiceLib.Common; } } - ~Job() + ~WindowsJob() { Dispose(false); } diff --git a/v2rayN/ServiceLib/Manager/AppManager.cs b/v2rayN/ServiceLib/Manager/AppManager.cs index 2f5ccb64..16aa4253 100644 --- a/v2rayN/ServiceLib/Manager/AppManager.cs +++ b/v2rayN/ServiceLib/Manager/AppManager.cs @@ -8,7 +8,7 @@ public sealed class AppManager private Config _config; private int? _statePort; private int? _statePort2; - private Job? _processJob; + private WindowsJob? _processJob; public static AppManager Instance => _instance.Value; public Config Config => _config; diff --git a/v2rayN/ServiceLib/Services/ProcessService.cs b/v2rayN/ServiceLib/Services/ProcessService.cs index db3a95ac..06e27d52 100644 --- a/v2rayN/ServiceLib/Services/ProcessService.cs +++ b/v2rayN/ServiceLib/Services/ProcessService.cs @@ -178,5 +178,6 @@ public class ProcessService : IDisposable } _isDisposed = true; + GC.SuppressFinalize(this); } }