Mihir Solanki <mi**********@h otmail.com> wrote:
The difference between the Invoke and DynamicInvoke is Invoke requires the
target object that instantiated the method as parameter to execute the method.
But DynamicInvoke doesn't require the target object without which it calls
the method dynamically with the parameter list.
If the method is static then null can be passed as target object in Invoke
during which Invoke is similar to that of DynamicInvoke.
Invoke
Delegate objdel = new Delegate (this. Meth1);
Objdel.Method.I nvoke (targetobject, new object [] {"params"});
That's not calling the delegate's Invoke method. It's calling the
MethodInfo's Invoke method.
Here's an example calling a delegates *actual* Invoke method:
using System;
public class Test
{
static void Main()
{
EventHandler x = new EventHandler(Fo o);
x.Invoke("hello ", null);
}
static void Foo (object sender, EventArgs e)
{
Console.WriteLi ne (sender);
}
}
The difference between Invoke and DynamicInvoke is that the parameters
to Invoke depend on the delegate itself - the method has the same
signature as the delegate. DynamicInvoke has a "fixed" signature, and
it dynamically calls Invoke with the appropriate parameters.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too