Przeglądaj źródła

Fix potential bug

SenGao 3 tygodni temu
rodzic
commit
2a2e5ace7b

+ 16 - 13
Tools/AlarmInfoServerSim/ViewModels/StatusBarViewModel.cs

@@ -32,19 +32,22 @@ public partial class StatusBarViewModel : ObservableObject
 
     private void OnConnectionChanged(object? sender, (bool, UniversalNetFrame451.IO.TcpConnection) e)
     {
-        if(e.Item1)
+        App.Current.Dispatcher.Invoke(() =>
         {
-            Status = "Connected";
-            RemoteIp = e.Item2.RemoteEndPoint.Address.ToString();
-            RemotePort = e.Item2.RemoteEndPoint.Port.ToString();
-            _logService.Log($"Get a connection from {RemoteIp}:{RemotePort}");
-        }
-        else
-        {
-            Status = "Disconnected";
-            RemoteIp = "Unknown";
-            RemotePort = "Unknown";
-            _logService.Log($"The connection lost");
-        }
+            if (e.Item1)
+            {
+                Status = "Connected";
+                RemoteIp = e.Item2.RemoteEndPoint.Address.ToString();
+                RemotePort = e.Item2.RemoteEndPoint.Port.ToString();
+                _logService.Log($"Get a connection from {RemoteIp}:{RemotePort}");
+            }
+            else
+            {
+                Status = "Disconnected";
+                RemoteIp = "Unknown";
+                RemotePort = "Unknown";
+                _logService.Log($"The connection lost");
+            }
+        });
     }
 }