【修改】判断本地判分是否已经运行

This commit is contained in:
MSI\letre
2025-07-14 09:57:52 +08:00
parent 885f70fb56
commit 3783a98b92

View File

@@ -72,7 +72,7 @@ class Program
UseShellExecute = true // 或 false根据需要
};
// 检测一下端口是否被占用48080
if (!IsPortInUse(48082))
if (!IsPortInUse("judgement"))
{
Process.Start(startInfo);
}
@@ -516,19 +516,29 @@ class Program
list.Add(sql.Substring(start));
return list;
}
public static bool IsPortInUse(int port)
public static bool IsPortInUse(string name)
{
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
foreach (var proc in Process.GetProcesses())
{
if (tcpi.LocalEndPoint.Port == port)
try
{
return true; // 端口被占用
// 主窗口句柄不为 0表示是一个窗口程序用户级应用
if (proc.SessionId != 0 &&
proc.Responding)
{
if (proc.ProcessName.Contains(name))
{
var procs = Process.GetProcessById(proc.Id);
return true;
}
}
}
catch
{
// 一些系统进程可能抛异常,忽略
}
}
return false; // 端口可用
}