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 InvokeWrappedDe legate (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. 5 9739
On Sun, 02 Nov 2008 17:50:04 -0700, puzzlecracker <ir*********@gm ail.com>
wrote:
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.
In other words, DynamicInvoke() provides for late-bound, dynamic method
invocations, while the Invoke() method provides for statically typed,
early-bound invocations.
Pete
On Nov 2, 7:04 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Sun, 02 Nov 2008 17:50:04 -0700, puzzlecracker <ironsel2...@gm ail.com>
wrote:
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
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
puzzlecracker wrote:
On Nov 2, 7:04 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Sun, 02 Nov 2008 17:50:04 -0700, puzzlecracker <ironsel2...@gm ail.com>
wrote:
On Sun, 02 Nov 2008 18:30:38 -0700, puzzlecracker <ir*********@gm ail.com>
wrote:
[...]
>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'm not sure what you mean here. It's not speculation on my part that
Invoke() is generated by the compiler. It _is_ generated by the
compiler. You appear to be saying that code would not be able to call
Invoke() if that method weren't generated by the compiler, but that's not
true at all. Code can and does do just that.
I thought it was predifined by the system each time delegate is
defined/instantiated.
The "system" is the compiler. As far as the run-time is concerned, it's
just like any other type, at least in that by the time your code is
actually executing, you've got a well-defined type with statically defined
members (not to be confused with "static members", of course).
Invoke becomes less clear to me.
Hopefully the above clears things up a bit.
Pete
On Sun, 02 Nov 2008 18:13:20 -0700, Peter Duniho
<Np*********@nn owslpianmk.comw rote:
[...]
>If it's generated by compiler then we cannot call it, which is not the case.
I'm not sure what you mean here. It's not speculation on my part that
Invoke() is generated by the compiler. It _is_ generated by the
compiler. You appear to be saying that code would not be able to call
Invoke() if that method weren't generated by the compiler, but that's
not true at all. Code can and does do just that.
Er, obviously that should read "if that method was generated by the
compiler". Sorry for the typo. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ben Reese |
last post by:
Simplified.
I have 2 forms running on seperate threads (and message queues)
I am having some odd problems with with the form on the second
Thread/message queue freezing and/or dyinig, seemingly at random.
I have been carfull always to call Form2.Invoke(someDelegate) Whenever I
want to access a method on the second form from the first.
I have tracked down 1 remaining occurence Where from 1 wants to disable a
button on form 2
|
by: Tom |
last post by:
Hi Everybod
I want to update some controls in a form from another threads. I did it by passing the form to that thread and calling a delegate with Form1.Invoke, I want to have just one delegeate for all of my controls in the Form and dont define one delegate for each control. Some thing like to have a switch case in that delegate fucntion and passing control name to it..
what is the impact of this method in comparison with...
|
by: Christian Westerlund |
last post by:
Hi!
I'm trying to use P/Invoke and a Method which takes an IntPtr where I am
supposed to put an address to a method which the native method will use
to communicate back to me. How do I convert a method to an IntPtr?
/ Christian
|
by: rawCoder |
last post by:
Hi
I am having this InvalidOperationException with message Cannot call Invoke
or InvokeAsync on a control until the window handle has been created
This is raised when i try to invoke a method with arguments
I need to do this as the method is being called Asynchronously from
elsewhere using delegate's BeginInvoke method.
The form is well created/initialized yet the messages states otherwise.
|
by: Terry Olsen |
last post by:
I'm running an asynchronous Socket. In the ReceiveCallback method, I need
to append what is received to a textbox on the main form. I have this code:
Private Sub ToChatWindow(ByVal msg As String)
txtChat.AppendText(msg)
End Sub
I've never used a delegate or invoke before and I'm rather confused on the
topic. Hope someone can help.
| |
by: dani kotlar |
last post by:
Is it possible to pass the Invoke or BeginInvoke functions as a
parameter a delegate encapsulating a function with a non empty set of
parameters? How is it done?
|
by: Dom |
last post by:
I'm teaching myself about delegates and the Invoke method, and I have
a few newbie questions for the gurus out there:
Here are some CSharp statements:
1. public delegate void MyDelegate (int k, string s)
2. MyDelegate MyDelegateVar = MyMethod
3. MyForm.Invoke (MyDelegateVar)
Some questions:
|
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
|
by: balabaster |
last post by:
I have a class that I want to make thread-safe and am investigating the ISyncronizeInvoke interface and wondering just what it will take to implement this interface. So far the basic concept of my code is:
Public Class MyClass1
Implements System.ComponentModel.ISynchronizeInvoke
Private _InvokeRequired As Boolean = False
Public Function BeginInvoke(ByVal method As System.Delegate, ByVal args() As Object) As...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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();...
|
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...
| |
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...
| |