By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,685 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,685 IT Pros & Developers. It's quick & easy.

Store added event handlers

P: n/a

I add event handlers to different events of objects of different type. In an
array or arraylist, I want to store the information about which events I
added. Later, I want to process the arraylist and detach all the event
handlers. My problem is that I don't know which information to store. When
removing the handlers in a loop, the most important thing is that I don't
want to distinguish between the different object types and events, so I want
the code to be based on the basic Delegate/MulticastDelegate classes. I have
currently no clue how to do it. Something like:

dim o as new class1

addhandler o.ev1, addressof OnEv1
addhandler o.ev2, addressof OnEv2
for each i as Item in al 'al=arraylist, item=new class (see below)
removehandler i.???, i.???

Each time I use Addhandler I will create a new Item object and add it to the
arraylist. Though, I don't know what to store in an Item object. I thought
it must be a MulticastDelegate (the event) and a Delegate (the event
handler), but I am not able to store a reference to o.ev1 or o.ev2.

Is it possible at all or do I have to handle each event and object
individually? (btw, reflection is not an option) Thanks in advance.


Jul 9 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
"Mudhead" <no*****@here.comschrieb im Newsbeitrag
Look into EventHandlerList class
Thanks for the link.

Meanwhile I found out that it is not possible what I was trying. The problem
is what's going on under the hood when adding/removing event handlers: The
AddHandler keyword doesn't expect an object as the first argument, but it's
the /name/ of an event. If it was an object, it would be possible to store a
reference. Everything done internally by executing Addhandler is specific to
the class and to the event. As it's specific, there is no multipurpose
solution that enables me storing references to events in the way intended.

Jul 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.