public static void TryToGetLanList(Action<ServerInformation> foundCallback, IEnumerable<int> ports) {
Parallel.ForEach(
GetBroadcastAddresses()
.SelectMany(x => ports.Select(y => new {
BroadcastIp = x,
Port = y
})),
(entry, ipLoopState) => {
var found = BroadcastPing(entry.BroadcastIp, entry.Port);
if (found == null) return;
try {
var information = TryToGetInformationDirect(found.Ip, found.Port);
if (information == null) return;
information.IsLan = true;
Application.Current.Dispatcher.InvokeAsync(() => foundCallback(information));
} catch (Exception e) {
Logging.Write("[LAN SERVERS] Error: " + e);
}
});
}