public static async Task TryToGetLanListAsync(ItemAddCallback <ServerInformation> foundCallback, IProgress <AsyncProgressEntry> progress = null, CancellationToken cancellation = default) { var holder = progress == null ? null : new Progress(); DispatcherTimer timer = null; try { if (holder != null) { timer = new DispatcherTimer(DispatcherPriority.Background, Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher) { Interval = TimeSpan.FromSeconds(0.1), IsEnabled = true }; timer.Tick += (sender, args) => { progress.Report(new AsyncProgressEntry($"Scanned {holder.Current} of {holder.Total}", holder.Current, holder.Total)); }; } await Task.Run(() => { TryToGetLanList(foundCallback, PortsDiapason.Create(SettingsHolder.Online.LanPortsEnumeration), holder, cancellation); }, cancellation); } finally { if (holder != null && timer != null) { timer.IsEnabled = false; } } }
public static void TryToGetLanList(ItemAddCallback <ServerInformation> foundCallback) { TryToGetLanList(foundCallback, PortsDiapason.Create(SettingsHolder.Online.LanPortsEnumeration), null, default); }