Skip to content

Commit 1baf420

Browse files
authored
[Server] Fix Sampling Group creating a new long running task for every Client AddMonitoredItems Method Call (#2984)
* fix Sampling Group creating a new long running task for every Client Add MonitoredItems Method Call * reset also on shutdown * dispose shutdown event
1 parent 7cbeee7 commit 1baf420

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Libraries/Opc.Ua.Server/NodeManager/SamplingGroup.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void Startup()
106106
{
107107
m_shutdownEvent.Reset();
108108

109-
Task.Factory.StartNew(() => {
109+
m_samplingTask = Task.Factory.StartNew(() => {
110110
SampleMonitoredItems(m_samplingInterval);
111111
}, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach);
112112
}
@@ -121,6 +121,9 @@ public void Shutdown()
121121
{
122122
m_shutdownEvent.Set();
123123
m_items.Clear();
124+
Utils.SilentDispose(m_samplingTask);
125+
m_samplingTask = null;
126+
Utils.SilentDispose(m_shutdownEvent);
124127
}
125128
}
126129

@@ -243,7 +246,7 @@ public bool ApplyChanges()
243246
m_itemsToRemove.Clear();
244247

245248
// start the group if it is not running.
246-
if (m_items.Count > 0)
249+
if (m_samplingTask == null && m_items.Count > 0)
247250
{
248251
Startup();
249252
}
@@ -487,6 +490,7 @@ private void DoSample(object state)
487490
private Dictionary<uint, ISampledDataChangeMonitoredItem> m_items;
488491
private ManualResetEvent m_shutdownEvent;
489492
private List<SamplingRateGroup> m_samplingRates;
493+
private Task m_samplingTask;
490494
#endregion
491495
}
492496
}

0 commit comments

Comments
 (0)