public static IPHostEntry EndResolve(IAsyncResult asyncResult)
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(null, asyncResult);
}
IPHostEntry ipHostEntry;
try
{
ipHostEntry = TaskToApm.End <IPHostEntry>(asyncResult);
}
catch (SocketException ex)
{
IPAddress?address = asyncResult switch
{
Task t => t.AsyncState as IPAddress,
TaskToApm.TaskAsyncResult twar => twar._task.AsyncState as IPAddress,
_ => null
};
if (address is null)
{
throw; // BeginResolve was called with a HostName, not an IPAddress
}
if (NetEventSource.IsEnabled)
{
NetEventSource.Error(null, ex);
}
ipHostEntry = CreateHostEntryForAddress(address);
}
if (NetEventSource.IsEnabled)
{
NetEventSource.Exit(null, ipHostEntry);
}
return(ipHostEntry);
}