473,813 Members | 2,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Whats with DynamicInvoke?

Hi to all.
Whats the difference between DynamicInvoke and Invoke methods of the
Delegate class?
Thanks in advance.
Nov 22 '05 #1
3 19286
Hi Amir,

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"});

If the method is static then
Objdel.Method.I nvoke (null, new object [] {"params"});

DynamicInvoke
Objdel.DynamicI nvoke (new object [] params);
Mihir Solanki
http://www.mihirsolanki.com
Hi to all.
Whats the difference between DynamicInvoke and Invoke methods of the
Delegate class?
Thanks in advance.

Nov 22 '05 #2
So why do I need both of them?
Why can't I always use Invoke method?
Is there a substantial difference between the two?

"Mihir Solanki" wrote:
Hi Amir,

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"});

If the method is static then
Objdel.Method.I nvoke (null, new object [] {"params"});

DynamicInvoke
Objdel.DynamicI nvoke (new object [] params);
Mihir Solanki
http://www.mihirsolanki.com
Hi to all.
Whats the difference between DynamicInvoke and Invoke methods of the
Delegate class?
Thanks in advance.


Nov 22 '05 #3
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
Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8182
by: Arif Khan | last post by:
How can I pass, by ref or out parameter values when calling DynamicInvoke Method. e.g. Here is my Delegate: public delegate int BinaryOp(int x, int y, out double z, ref bool overflow); Here is how I am creating a delegate object for "Subtract" method. BinaryOp op2 = (BinaryOp) Delegate.CreateDelegate(dt, tt,"Subtract"); Here is how I am creating parameters object. Notice t and ret are
4
2009
by: David Lozzi | last post by:
OK simple question. Whats the default value for an string() array? sub LoadStuff(byval one as integer, byval two as string, optional byval three() as string = ??) Its driving me nuts! Thanks! --
4
2773
by: sophie | last post by:
Whats going on here: Read in a number as a string: scanf("%s", &number); number = 12345, for arguements sake Print it like this its fine:
7
2237
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell me why? Its probably sooooooo obvious, but it is 1.19 am! Thanks. www.thunderin.co.uk/
0
1258
by: mickeymicks | last post by:
hi all! <i'm fairly new to csharp (and dotnet) and is particularly confused with delegates and events.. so forgive me if im a bit dense..> Is there any major concern that i need to think about when triggerring an event or a delegate using DynamicInvoke() versus simply calling the event.. MyEvent.DynamicInvoke(sender, args);
1
3006
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
Jon Skeet wrote in the .NET general newsgroup 11/17/2005: "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." So far I have seen DynamicInvoke only used in conjunction with generics event arguments. Is there any other...
0
1795
by: flyingchen | last post by:
using System; using System.Windows.Forms; using System.Threading; using System.ComponentModel; namespace ProgressControl.Core { public delegate object Execute(params object args); public class ProgressController
1
2716
by: Terry Olsen | last post by:
I'm using the SciLexer.dll to write a code editor for an in-house scripting language. I have the editor window up on a form but I need to use it's API. I've used the following commands to load the dll: Private scihWnd As Integer 'Scintilla's hWnd Private SciFunc As Integer 'Scintilla's Main Function Call Private sciptr As Integer 'Scintilla's Direct Pointer Private scihmod As Integer 'Scintilla's hMod scihmod =...
5
9737
by: puzzlecracker | last post by:
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)
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10139
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.