I am writing an SDK based application that monitors tags through a PointList's EventPipe.
The number of tags increases during the use of the service. I provide a web service that allows other applications to subscribe to tags they are interested in. The problem is that when a new tag is monitored, the event is fired the same number of times as there are items in the PointList.
I have a couple of fields in my C# class:
private PISDK.PointList pointList = new PISDK.PointList();
And the event:
public event TriggerActivatedHandler TriggerActivatedEvent;
The delegate is defined in an interface that my class implements:
public delegate void TriggerActivatedHandler(string thing, object value, DateTime timeStamp);
And these are used in response the subscription request, like this:
public void Subscribe(string tag)
if (pointList.Count > 0)
// reuse the defined _pipe
catch (Exception e)
_pipe = (PISDK.IEventPipe2)pointList.Data.EventPipe;
_ptEvent = (PISDK._DEventPipeEvents_Event)_pipe;
_ptEvent.OnNewValue += new PISDK._DEventPipeEvents_OnNewValueEventHandler(_ptEvent_OnNewValue);
Now, whenever one of the monitored tags fires, the _ptEvent assumes that there are as many listeners as there are points in the PointList.
This is the event handler:
if (this.TriggerActivatedEvent == null)
// if nobody listens we have to do nothing
if (_pipe.Count == 0)
Array events = _pipe.TakeAll();
foreach (PISDK.PIEventObject peo in events)
PISDK.PointValue pv = (PISDK.PointValue)peo.EventData;
this.TriggerActivatedEvent(pv.PIPoint.Name, pv.PIValue.Value.ToString(), pv.PIValue.TimeStamp.LocalDate); // this is the function that fires too often?
So, I get too many events.
The behaviour is identical, if you first do a _ptEvent.OnNewValue -= to remove the previous handler, and then do a += is again on the updated PointList.
I do not quite understand what is going wrong.
Jan van der Ven