Troubleshooting Duplicate OPC UA Data-Change Events

Jason IP2 min read
OPC / OPC UAOther ManufacturerTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

When one data-change handler is registered for every monitored item, each notification invokes every accumulated handler. The observed event totals follow that multiplication: one tag produces 60 callbacks in 60 seconds, two tags produce 240, and three tags produce 540. Register the client-level handler once, then create the monitored-item subscriptions separately.

Identify the callback multiplication

The tags change every 1000 ms, and the requested scan rate is also 1000 ms. Over 60 seconds, the expected total for N tags is 60 × N. The observed total is 60 × N², indicating that N notifications are each being delivered to N registered copies of the same handler.

Tags Expected callbacks Observed callbacks Registered-handler multiplier
1 60 60 1×
2 120 240 2×
3 180 540 3×

Separate handler registration from item subscription

The faulty pattern executes both statements for each monitored item. Although each call subscribes another node, it also adds another delegate to MonitoredItemChanged. The event then invokes every registered delegate for every incoming data change.

m_EasyUAClient.MonitoredItemChanged +=
    new EventHandler<EasyUAMonitoredItemChangedEventArgs>(
        m_EasyUAClient_MonitoredItemChanged);

m_EasyUAClient.SubscribeMonitoredItem(
    i_TransactionInfo.OpcServerUrl,
    nodeId,
    i_TransactionInfo.ScanRateSeconds.Value * 1000,
    state);

Correct the subscription sequence

  1. Create or initialize m_EasyUAClient.
  2. Attach m_EasyUAClient_MonitoredItemChanged to MonitoredItemChanged once, outside the per-tag subscription loop.
  3. Subscribe each required nodeId without attaching the handler again.
  4. If loop performance is slow, replace repeated SubscribeMonitoredItem calls with one SubscribeMultipleMonitoredItems call to reduce calls to the OPC UA server.

The multiple-item method is a performance optimization; the callback-count correction comes from registering the event handler only once.

Verify the corrected callback count

Repeat the 60-second test with tags changing every 1000 ms and the requested interval set to 1000 ms. The corrected totals should return to 60 callbacks for one tag, 120 for two tags, and 180 for three tags. If the count still exceeds 60 × N, inspect every initialization and reconnect path for another execution of the MonitoredItemChanged += statement.

FAQ

Why do two OPC UA tags produce 240 callbacks in 60 seconds?

Two tag subscriptions also registered two copies of the event handler. Each of the expected 120 data-change notifications invoked both handlers, producing 240 callbacks.

Where should I register MonitoredItemChanged?

Register MonitoredItemChanged once during client initialization, outside the loop that calls SubscribeMonitoredItem for each node.

Should I use SubscribeMultipleMonitoredItems?

Use SubscribeMultipleMonitoredItems when repeated single-item subscriptions cause slow loop performance. It reduces calls to the OPC UA server, but handler registration must still occur only once.

Back to blog