Comparing .NET delegates
I'm having some problems comparing delegates. In all sample projects I
create, I can't get the problem to occur, but there is definitely a problem
with my production code.
I can't give all the code, as there's simply too much, but here's the
I have a connection object which connects to a custom back-end server of one
type or another. Clients of this connection object send requests via a
method (e.g. connection.SendRequest()) and one of parameters to this call is
a callback delegate.
At a later point, the client may attempt to cancel all the requests specific
to the delegate that was passed in. It's in this method that I'm doing the
delegate comparisons. Consistently, the delegates never match, so the
requests can't be cancelled.
In the client code, I've tried passing in the method name directly or a
delegate instance, created with the method as a parameter. I get the same
results either way.
When debugging, I notice something strange, and no doubt the cause of the
The stored delegate refers to the actual method to call:
.Method: the actual method name
.Target: the actual class name where the method resides
...but the delegate passed in, refers to an Invoke method:
.Target: the delegate type!
So, I understand why the comparison is failing. They don't appear to be the
same delegate at all! But I don't understand why the passed in delegate
refers to the Invoke method, instead of the actual target method.
Can someone explain to me what's going on? And moreover, does anyone have a
solution to the problem?
By Phil Weber in forum .NET
Last Post: 10-01-2003, 12:00 AM
Last Post: 02-28-2003, 03:43 PM
By Patrick Troughton in forum .NET
Last Post: 02-12-2003, 09:31 AM
By AutomatedQA Corp in forum .NET
Last Post: 03-20-2002, 05:28 AM
By Seth Grossman [MSFT] in forum .NET
Last Post: 02-28-2002, 01:44 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center