1

I want to call a function as soon as an event from an external library occurs.

I have an array of camera objects (different cameras) which create an event as soon as they grab an image (triggered externally). The cameras are defined by an external Library (Basler) and were defined in the code before so the event is defined as follows:

cameras(i).StreamGrabber.ImageGrabbed

I created a sub

Sub ImageGrabEvent(sender As Object, e As EventArgs)
    MsgBox("Aha")
End Sub</code>

and tried to register in the main part with

AddHandler cameras(i).StreamGrabber.ImageGrabbed, AddressOf (ImageGrabEvent)

and also tried

AddHandler cameras(i).StreamGrabber.ImageGrabbed, ImageGrabEvent()

and variations with "new" or whatever.

Extra Challenge: Any camera can raise the event, how can I identify in my sub which camera did it?

Blackwood
  • 4,504
  • 16
  • 32
  • 41
Martin S
  • 15
  • 4
  • Should just be the first option you tried but without the parantheses. `AddressOf ImageGrabEvent`. And sender should tell you which object raised the event – A Friend Jun 17 '16 at 13:01

1 Answers1

1

You should not have brackets (parentheses) around the handler method so this:

AddHandler cameras(i).StreamGrabber.ImageGrabbed, AddressOf (ImageGrabEvent)

should be:

AddHandler cameras(i).StreamGrabber.ImageGrabbed, AddressOf ImageGrabEvent

The sender object gives you the object that raised the event

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • Correct Answer! Had one more error: The Main Sub was declared as shared which also raised an error while declaring the AddHandler – Martin S Jun 26 '16 at 19:20