There are two ways in which you can subscribe for an event fired by the node event sink service:
-
Subscribe for a broadcased event - this is achieved by adding an event handler for one of the node events exposed by the service. For example:
C# Copy Code... // subscribe for a broadcasted event nodeEventSinkService.NodePropertyChanged += new NodePropertyEventHandler(OnAnyNodePropertyChanged); ... private void OnAnyNodePropertyChanged(NNodePropertyEventArgs args) { }
Visual Basic Copy Code... ' subscribe for a broadcasted event AddHandler nodeEventSinkService.NodePropertyChanged, AddressOf OnAnyNodePropertyChanged ... Private Sub OnAnyNodePropertyChanged(ByVal args As NNodePropertyEventArgs) End Sub
-
Install an event listener - this is achieved with the help of the AddNodeEventListener method. For example:
C# Copy Code... // install node event listener for the NodePropertyChanged event nodeEventSinkService.AddNodeEventListener("NodePropertyChanged", node1, new NodePropertyEventHandler(OnNode1PropertyChanged)); ... private void OnNode1PropertyChanged(NNodePropertyEventArgs args) { }
Visual Basic Copy Code... ' install node event listener for the NodePropertyChanged event Dim handler As NodePropertyEventHandler = AddressOf OnNode1PropertyChanged nodeEventSinkService.AddNodeEventListener("NodePropertyChanged", node1, handler) ... Private Sub OnNode1PropertyChanged(ByVal args As NNodePropertyEventArgs) End Sub
From a nodes' point of view it is enough to only call the respective FireXXX method in order to update all listeners and broadcasted event subscribers. By design the service first invokes the event handlers of the registered node listeners and then invokes the broadcasted event handlers.