Raise Events from Objects In a Collection?

  • Thread starter Thread starter Eric Robinson
  • Start date Start date
E

Eric Robinson

My application creates a number of objects for monitoring servers. Each
object monitors one server. When an object detects certain conditions in the
server, it should raise an event to notify the parent application (not the
collection object).

I know this has been discussed before, but I can't find a definitive HOWTO
that is current. Can someone point me in the right direction?

--Eric
 
For each of the objects (when declared), use the following code:

Public Sub DeclareObject()

object = new object...
AddHandler object.<the object's event>, AddressOf <the sub that you
wish to call upon the event>
...add to list...

End Sub

You would use RemoveHandler in the same fashion.

Also, to pass back the identity of the object in the list that is
calling the event, simply place a parameter in the event as follows:

Public Class TheObject

Public Event SomeEventToRaise(sender as TheObject)

Public Sub blah()

...
RaiseEvent SomeEventToRaise(me)
...

End Sub

End Class

and then you would put a matching parameter in the target of the
AddHandler so that it would recieve the identity of the object.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top