Update TryReleaseUsedTcpPort

This commit is contained in:
ChsBuffer
2021-03-24 11:14:36 +08:00
parent 452c5ec67c
commit 32d3e97288

View File

@@ -193,9 +193,10 @@ namespace Netch.Controllers
{ {
foreach (var p in PortHelper.GetProcessByUsedTcpPort(port)) foreach (var p in PortHelper.GetProcessByUsedTcpPort(port))
{ {
string fileName;
try try
{ {
_ = p.MainModule!.FileName; fileName = p.MainModule!.FileName;
} }
catch (Exception e) catch (Exception e)
{ {
@@ -203,16 +204,14 @@ namespace Netch.Controllers
continue; continue;
} }
if (p.MainModule.FileName.StartsWith(Global.NetchDir)) if (fileName.StartsWith(Global.NetchDir))
{ {
p.Kill(); p.Kill();
p.WaitForExit(); p.WaitForExit();
} }
else else
{ {
throw new MessageException(i18N.TranslateFormat("The {0} port is used by {1}.", throw new MessageException(i18N.TranslateFormat("The {0} port is used by {1}.", $"{portName} ({port})", $"({p.Id}){fileName}"));
$"{portName} ({port})",
$"({p.Id}){p.MainModule.FileName}"));
} }
} }