axihttp DNS线程安全

This commit is contained in:
sin365 2025-08-20 15:22:02 +08:00
parent 2356fd7448
commit 224e0d1126

View File

@ -166,20 +166,23 @@ public static class AxiHttp
public static IPAddress GetDnsIP(string str) public static IPAddress GetDnsIP(string str)
{ {
if (!dictIP2Address.ContainsKey(str)) lock (dictIP2Address)
{ {
IPHostEntry host = Dns.GetHostEntry(str); if (!dictIP2Address.ContainsKey(str))
IPAddress ip = null;
foreach (var item in host.AddressList)
{ {
if (item.AddressFamily == AddressFamily.InterNetwork) IPHostEntry host = Dns.GetHostEntry(str);
IPAddress ip = null;
foreach (var item in host.AddressList)
{ {
ip = item; break; if (item.AddressFamily == AddressFamily.InterNetwork)
{
ip = item; break;
}
} }
dictIP2Address[str] = ip;
} }
dictIP2Address[str] = ip; return dictIP2Address[str];
} }
return dictIP2Address[str];
} }
public enum AxiDownLoadMode public enum AxiDownLoadMode