diff --git a/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/AlarmsViewModel.cs b/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/AlarmsViewModel.cs
index 42a18a9..d67fd54 100644
--- a/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/AlarmsViewModel.cs
+++ b/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/AlarmsViewModel.cs
@@ -215,6 +215,16 @@ public partial class AlarmsViewModel : ObservableObject
ActiveAlarmCount = 0;
}
+ ///
+ /// Re-hooks event handlers to the service after a server-side reconnect.
+ /// Safe to call when already attached (duplicate += is a no-op in .NET multicast delegates).
+ ///
+ public void Reattach()
+ {
+ _service.AlarmEvent -= OnAlarmEvent;
+ _service.AlarmEvent += OnAlarmEvent;
+ }
+
///
/// Unhooks event handlers from the service.
///
diff --git a/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/MainWindowViewModel.cs b/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/MainWindowViewModel.cs
index c757bd6..a3beb9f 100644
--- a/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/MainWindowViewModel.cs
+++ b/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/MainWindowViewModel.cs
@@ -166,6 +166,8 @@ public partial class MainWindowViewModel : ObservableObject
{
case ConnectionState.Connected:
StatusMessage = $"Connected to {EndpointUrl}";
+ Subscriptions?.Reattach();
+ Alarms?.Reattach();
break;
case ConnectionState.Reconnecting:
StatusMessage = "Reconnecting...";
@@ -177,6 +179,8 @@ public partial class MainWindowViewModel : ObservableObject
StatusMessage = "Disconnected";
SessionLabel = string.Empty;
RedundancyInfo = null;
+ Subscriptions?.Teardown();
+ Alarms?.Teardown();
BrowseTree?.Clear();
ReadWrite?.Clear();
Subscriptions?.Clear();
diff --git a/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/SubscriptionsViewModel.cs b/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/SubscriptionsViewModel.cs
index d4ea3fa..fad17f3 100644
--- a/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/SubscriptionsViewModel.cs
+++ b/src/Client/ZB.MOM.WW.OtOpcUa.Client.UI/ViewModels/SubscriptionsViewModel.cs
@@ -265,6 +265,16 @@ public partial class SubscriptionsViewModel : ObservableObject
SubscriptionCount = 0;
}
+ ///
+ /// Re-hooks event handlers to the service after a server-side reconnect.
+ /// Safe to call when already attached (duplicate += is a no-op in .NET multicast delegates).
+ ///
+ public void Reattach()
+ {
+ _service.DataChanged -= OnDataChanged;
+ _service.DataChanged += OnDataChanged;
+ }
+
///
/// Unhooks event handlers from the service.
///