Store added event handlers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Armin Zingler

    #1

    Store added event handlers

    Hi,

    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/MulticastDelega te 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.???
    next

    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 MulticastDelega te (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.



    Armin

  • Armin Zingler

    #2
    Re: Store added event handlers

    "Mudhead" <nowhere@here.c omschrieb im Newsbeitrag
    news:OWU7w62wHH A.4544@TK2MSFTN GP05.phx.gbl...
    Look into EventHandlerLis t class
    >
    http://weblogs.asp.net/rosherove/arc...31/344773.aspx
    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.


    Armin

    Comment

    Working...