瀏覽代碼

Fix potential bug

SenGao 3 周之前
父節點
當前提交
2a2e5ace7b
共有 1 個文件被更改,包括 16 次插入13 次删除
  1. 16 13
      Tools/AlarmInfoServerSim/ViewModels/StatusBarViewModel.cs

+ 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");
+            }
+        });
     }
 }