Invoke vs. DynamicInvoke method in the delegate

P

puzzlecracker

I've just discovered DynamicInvoke methods while reading Jon's
threading article. And my question is how it's different from a
regular invoke method?

In this method:

/// <summary>
/// Invokes the wrapped delegate synchronously
/// </summary>
static void InvokeWrappedDelegate (Delegate d, object[] args)
{
d.DynamicInvoke(args);
}


Perhaps it parses arguments from object[] one by one, converting to
appropriate type, and passes them to delegate -- I am just guessing.
 
P

puzzlecracker

I've just discovered DynamicInvoke methods while reading Jon's
threading article. And my question is how it's different from a
regular invoke method?

Perhaps it parses arguments from object[] one by one, converting to
appropriate type, and passes them to delegate -- I am just guessing.

I don't think it does. I believe that the arguments do need to match the
target method's declared types.

I admit, I have little first-hand information about DynamicInvoke(). But,
my understanding is that it's useful when you've got a delegate for which
the signature isn't known at compile time. It allows you to build the
argument list dynamically and pass it without matching a specific
signature.

Note that the Invoke() method is not part of the Delegate class per se,
but is generated for each delegate type by the compiler. It's done that
way so that the Invoke() method _does_ have a specific signature that
needs to be matched at compile-time.

If it's generated by compiler then we cannot call it, which is not the
case. I thought it was predifined by the system each time delegate is
defined/instantiated.
Invoke becomes less clear to me.
In other words, DynamicInvoke() provides for late-bound, dynamic method
invocations, while the Invoke() method provides for statically typed,
early-bound invocations.

I see, thanks
 
R

raylopez99

Where is the article? Some of what Jon writes is probably just for
effect, cutting edge stuff to show his peers he's on top of things
(just guessing) with no practical immeadiate importance. I would
guess DynamicInvoke --whatever it is-- is one of those things they
might put in C#4.

RL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top