Skip to content

Commit 2ac59a2

Browse files
committed
fix: dispatch Summary UI updates to UI thread on network change
ClearOnDisconnect() and SetActiveAdapter() modify ObservableCollections bound to LiveCharts and the process list. They were being called from the ETW background thread via the PropertyChanged chain, racing with the DispatcherTimer's FlushPendingTraffic() tick on the UI thread. This corrupted collection state after toggling adapters (e.g. Ethernet → off → WiFi → off → Ethernet), causing the Summary page to go silent. Fix: post NetworkStatus, ClearOnDisconnect, and SetActiveAdapter to Dispatcher.UIThread in OnNetworkChanged. Heavy work (ETW, PeriodicWork, History.ReloadProfiles) stays on the background thread. fix #107
1 parent d94ec56 commit 2ac59a2

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

OpenNetMeter/ViewModels/MainWindowViewModel.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Reflection;
33
using System.Windows.Input;
4+
using Avalonia.Threading;
45
using OpenNetMeter.Services;
56
using OpenNetMeter.Core.ViewModels;
67
using OpenNetMeter.PlatformAbstractions;
@@ -137,13 +138,20 @@ private void OnNetworkChanged(object? sender, NetworkSnapshotChangedEventArgs e)
137138
{
138139
if (string.IsNullOrWhiteSpace(e.AdapterName))
139140
{
140-
NetworkStatus = "Disconnected";
141-
Summary.ClearOnDisconnect();
141+
Dispatcher.UIThread.Post(() =>
142+
{
143+
NetworkStatus = "Disconnected";
144+
Summary.ClearOnDisconnect();
145+
});
142146
return;
143147
}
144148

145-
NetworkStatus = $"Connected : {e.AdapterName}";
146-
Summary.SetActiveAdapter(e.AdapterName);
149+
var adapterName = e.AdapterName;
150+
Dispatcher.UIThread.Post(() =>
151+
{
152+
NetworkStatus = $"Connected : {adapterName}";
153+
Summary.SetActiveAdapter(adapterName);
154+
});
147155
History.ReloadProfiles();
148156
}
149157

0 commit comments

Comments
 (0)