Re: what is wrong with this removehandler..?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?xJBvbm55?=

    #1

    Re: what is wrong with this removehandler..?

    Hi, I think I understand why it behaves how it behaves.
    A new feature of VB9 allows you to AddHandler for methods with slightly
    different signatures than signature of event is. However as I understand it
    some hidden routing method/delegate (which routes event to method with
    different signature) is created in compile time. And when you uses
    RemoveHandler another one is created which results to RemoveHandler removing
    handler which had been never attached. So, nothing happens and handler
    attached via AddHanlder is still attached.
    There are two ways how to prevent this behavior:
    1) Is prior VB9 - ensure that method (handler) as EXACTLY same signature as
    event (event delegate)
    2) Add handler is some way like this
    Dim HadlerDelegate = AddressOf MyMethod
    AddHandler TheObject.Event , HandlerDelegate
    then store HandlerDelegate somewhere and use it with RemoveHandler.
Working...