private async void StartScan() { DisplayStatusMessage = false; IsScanRunning = true; PreparingScan = true; // Measure the time StartTime = DateTime.Now; stopwatch.Start(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); EndTime = null; IPScanResult.Clear(); HostsFound = 0; // Change the tab title (not nice, but it works) Window window = Application.Current.Windows.OfType <Window>().FirstOrDefault(x => x.IsActive); if (window != null) { foreach (TabablzControl tabablzControl in VisualTreeHelper.FindVisualChildren <TabablzControl>(window)) { tabablzControl.Items.OfType <DragablzTabItem>().First(x => x.ID == _tabId).Header = IPRange; } } cancellationTokenSource = new CancellationTokenSource(); string[] ipHostOrRanges = IPRange.Replace(" ", "").Split(';'); // Resolve hostnames List <string> ipRanges = new List <string>(); try { ipRanges = await IPScanRangeHelper.ResolveHostnamesInIPRangeAsync(ipHostOrRanges, cancellationTokenSource.Token); } catch (OperationCanceledException) { IpScanner_UserHasCanceled(this, EventArgs.Empty); return; } catch (AggregateException exceptions) // DNS error (could not resolve hostname...) { IpScanner_DnsResolveFailed(this, exceptions); return; } IPAddress[] ipAddresses; try { // Create a list of all ip addresses ipAddresses = await IPScanRangeHelper.ConvertIPRangeToIPAddressesAsync(ipRanges.ToArray(), cancellationTokenSource.Token); } catch (OperationCanceledException) { IpScanner_UserHasCanceled(this, EventArgs.Empty); return; } IPAddressesToScan = ipAddresses.Length; IPAddressesScanned = 0; PreparingScan = false; // Add the range to the history AddIPRangeToHistory(IPRange); IPScannerOptions ipScannerOptions = new IPScannerOptions { Threads = SettingsManager.Current.IPScanner_Threads, Timeout = SettingsManager.Current.IPScanner_Timeout, Buffer = new byte[SettingsManager.Current.IPScanner_Buffer], Attempts = SettingsManager.Current.IPScanner_Attempts, ResolveHostname = SettingsManager.Current.IPScanner_ResolveHostname, ResolveMACAddress = SettingsManager.Current.IPScanner_ResolveMACAddress, ShowScanResultForAllIPAddresses = SettingsManager.Current.IPScanner_ShowScanResultForAllIPAddresses }; IPScanner ipScanner = new IPScanner(); ipScanner.HostFound += IpScanner_HostFound; ipScanner.ScanComplete += IpScanner_ScanComplete; ipScanner.ProgressChanged += IpScanner_ProgressChanged; ipScanner.UserHasCanceled += IpScanner_UserHasCanceled; ipScanner.ScanAsync(ipAddresses, ipScannerOptions, cancellationTokenSource.Token); }