Преглед изворни кода

尝试结束占用https的进程

xljiulang пре 4 година
родитељ
комит
bed28c53b9
1 измењених фајлова са 12 додато и 2 уклоњено
  1. 12 2
      FastGithub.ReverseProxy/ReverseProxyHostedService.cs

+ 12 - 2
FastGithub.ReverseProxy/ReverseProxyHostedService.cs

@@ -30,8 +30,18 @@ namespace FastGithub.ReverseProxy
                 const int HTTPSPORT = 443;
                 const int HTTPSPORT = 443;
                 if (TcpTable.TryGetOwnerProcessId(HTTPSPORT, out var pid))
                 if (TcpTable.TryGetOwnerProcessId(HTTPSPORT, out var pid))
                 {
                 {
-                    var process = Process.GetProcessById(pid);
-                    this.logger.LogError($"由于进程{process.ProcessName}({pid})占用了{HTTPSPORT}端口,{nameof(FastGithub)}的反向代理无法工作");
+                    try
+                    {
+                        Process.GetProcessById(pid).Kill();
+                    }
+                    catch (ArgumentException)
+                    {
+                    }
+                    catch (Exception)
+                    {
+                        var processName = Process.GetProcessById(pid).ProcessName;
+                        this.logger.LogError($"由于进程{processName}({pid})占用了{HTTPSPORT}端口,{nameof(FastGithub)}的反向代理无法工作");
+                    }
                 }
                 }
             }
             }
             return Task.CompletedTask;
             return Task.CompletedTask;