Skip to content

Commit 7ab3a75

Browse files
committed
Fix: Race condition on host/port scanned
1 parent f550c81 commit 7ab3a75

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

Source/NETworkManager/ViewModels/IPScannerViewModel.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ private async Task DetectIPRange()
536536
{
537537
IsSubnetDetectionRunning = true;
538538

539-
var localIP = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync(IPAddress.Parse("1.1.1.1"));
539+
var localIP = await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync(IPAddress.Parse(GlobalStaticConfiguration.Dashboard_PublicIPv4Address));
540540

541541
// Could not detect local ip address
542542
if (localIP != null)
@@ -716,7 +716,9 @@ public void OnClose()
716716
private void HostScanned(object sender, IPScannerHostScannedArgs e)
717717
{
718718
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
719-
new Action(delegate { Results.Add(e.Args); }));
719+
new Action(delegate {
720+
Results.Add(e.Args);
721+
}));
720722
}
721723

722724
/// <summary>
@@ -736,14 +738,19 @@ private void ProgressChanged(object sender, ProgressChangedArgs e)
736738
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
737739
private void ScanComplete(object sender, EventArgs e)
738740
{
739-
if (Results.Count == 0)
741+
// Run in UI thread with lower priority than HostScanned event
742+
// to ensure all results are added first #3285
743+
Application.Current.Dispatcher.Invoke(() =>
740744
{
741-
StatusMessage = Strings.NoReachableHostsFound;
742-
IsStatusMessageDisplayed = true;
743-
}
745+
if (Results.Count == 0)
746+
{
747+
StatusMessage = Strings.NoReachableHostsFound;
748+
IsStatusMessageDisplayed = true;
749+
}
744750

745-
IsCanceling = false;
746-
IsRunning = false;
751+
IsCanceling = false;
752+
IsRunning = false;
753+
}, DispatcherPriority.Background);
747754
}
748755

749756
/// <summary>

Source/NETworkManager/ViewModels/PortScannerViewModel.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,19 @@ private void ProgressChanged(object sender, ProgressChangedArgs e)
565565

566566
private void ScanComplete(object sender, EventArgs e)
567567
{
568-
if (Results.Count == 0)
568+
// Run in UI thread with lower priority than PortScanned event
569+
// to ensure all results are added first #3285
570+
Application.Current.Dispatcher.Invoke(() =>
569571
{
570-
StatusMessage = Strings.NoOpenPortsFound;
571-
IsStatusMessageDisplayed = true;
572-
}
572+
if (Results.Count == 0)
573+
{
574+
StatusMessage = Strings.NoOpenPortsFound;
575+
IsStatusMessageDisplayed = true;
576+
}
573577

574-
IsCanceling = false;
575-
IsRunning = false;
578+
IsCanceling = false;
579+
IsRunning = false;
580+
}, DispatcherPriority.Background);
576581
}
577582

578583
private void UserHasCanceled(object sender, EventArgs e)

0 commit comments

Comments
 (0)