Reputation: 676
This might be a dumb question, but I just can't get this to work.
Using a 3rd party C# library, I need to get live data via an Event Handler, It goes something like this:
Library.KEvents bnoEvent = new Library.KEvents();
envtsList.Add(bnoEvent);
/*
Some code to set bnoEvent up
*/
bnoEvent.OnEvent += new Library._IKEventsEvents_OnEventEventHandler(bnoEvent_OnEvent);
The function bnoEvent_OnEvent
is never executing.
The demo code I got (in VB) looks like this:
If KEventsA Is Nothing Then
Set KEventsA = New Library.KEvents
End If
/* Setting KEventA up */
The method that is being called is:
Private Sub KEvents_OnEvent(data As KType)
This drives me CRAZY! I cannot find any connection between this function and the KEventA
object! How does it know?
I know it is pretty hard to debug without knowing how this library actually works, but is there any major things I should be doing while registering for events beside declaring the function and adding it as a new eventHandler?
Upvotes: 0
Views: 1569
Reputation: 9024
Either use the Addhandler
Statement or the Handles
clause on the event sub. That is how VB sets up delegates.
If KEventsA Is Nothing Then
KEventsA = New Library.KEvents
Addhandler KEventsA.OnEvent, AddressOf KEvents_OnEvent
End If
Or
'must use this for declarations for this way
Private WithEvents KEventsA As New Library.KEvents
'then the method
Private Sub KEvents_OnEvent(data As KType) Handles KEventsA.OnEvent
C#
Library.KEvents KEventsA = new Library.KEvents;
KEventsA.OnEvent += new EventHandler(KEvents_OnEvent);
Upvotes: 1