Checking a VB handler in a C# class's invocation list

  • Thread starter Thread starter Tom Leylan
  • Start date Start date
T

Tom Leylan

I'm either passing the wrong thing, comparing the wrong thing or...
something else.

I have a CSharp base class which is used to fire events and in CSharp I have
defined a delegate for the custom eventhandler. I use this as a subclass
for classes created in VB.Net. I realize I can define it all in VB.Net but
I need it done this way. I can add an eventhandler in a VB.Net app to the
VB.Net object I've created and all the events are firing fine. I wanted to
add a couple of diagnostics to the CSharp base class.

I added a method named SubscriberCount which returns the size of the
InvocationList and that works fine. I can see it in my VB class and I can
make it visible to the app and that all works. Now I wanted to see if a
particular handler was in the InvocationList. I'm not trying to return the
list, I'm passing the AddressOf MyEventHandler but it never finds a match.

It is iterating through the list fine, I've traced everything I think I'm
comparing the wrong thing. Does anybody have a clue as to what I might be
doing wrong? I'm passing the addressof the handler in the VB.App to a
method in the VB.Class which passes it along to MyBase.IsSubscriber. I've
had that routine compare the object for each Delegate in the list (that
didn't seem to match) then I tried matching the .Target to each .Target
(didn't work) then I tried the object to the .Target and that didn't work.

I'm checking things in the watch window but I can't seem to see what it
wants. I noticed that VB doesn't actually care I can RemoveHandler even if
I haven't added it but now it's just become something I want to complete and
I'd rather not remove a handler that wasn't there in any case.

Thanks for any pointers, I've searched all over,
Tom
 
As I feared it was the 3rd option "something else". The good news is it
works the bad news is I can't count :-(
 
Back
Top