473,414 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Why Invoke() can be called on .NET framework delegates and not on my own????

Why doesn't this code compile???
Why can I call Invoke on .NET Framework defined delegates and not on
my own.

using System;

namespace DelegatesTest
{
public delegate void MyDelegate();

class MyClass
{
// .NET Framework defined delegates
public System.Threading.TimerCallback timerCallback = null;
public System.Timers.ElapsedEventHandler elapsedEventHandler = null;

// my own delegate
public DelegatesTest.MyDelegate myDelegate = null;

static void Main(string[] args)
{
MyClass myClass = new MyClass();

// OK
myClass.timerCallback.Invoke(null);
// OK
myClass.elapsedEventHandler.Invoke(null, null);
// NOT OK - will not compile
myClass.myDelegate.Invoke();
}
}
}

Don't look at the fact that the 3 delegates are not assigned any valid
method ... I tried writing the shortest possible example to explain my
problem.
Bob
Nov 16 '05 #1
3 1254

"Bob Rock" <an***************@yahoo.com> wrote in message
news:98**************************@posting.google.c om...
Why doesn't this code compile???
Why can I call Invoke on .NET Framework defined delegates and not on
my own.


It appears to be a bug in the 1.x compilers. The 2.0 compiler errors out on
all three Delegate::Invoke calls.

Nov 16 '05 #2
IIRC, to get it to work, just using "myDelegate();" to run the delegate.

--
William Stacey
MVP Directory Services
http://mvp.support.microsoft.com

"Bob Rock" <an***************@yahoo.com> wrote in message
news:98**************************@posting.google.c om...
Why doesn't this code compile???
Why can I call Invoke on .NET Framework defined delegates and not on
my own.

using System;

namespace DelegatesTest
{
public delegate void MyDelegate();

class MyClass
{
// .NET Framework defined delegates
public System.Threading.TimerCallback timerCallback = null;
public System.Timers.ElapsedEventHandler elapsedEventHandler = null;

// my own delegate
public DelegatesTest.MyDelegate myDelegate = null;

static void Main(string[] args)
{
MyClass myClass = new MyClass();

// OK
myClass.timerCallback.Invoke(null);
// OK
myClass.elapsedEventHandler.Invoke(null, null);
// NOT OK - will not compile
myClass.myDelegate.Invoke();
}
}
}

Don't look at the fact that the 3 delegates are not assigned any valid
method ... I tried writing the shortest possible example to explain my
problem.
Bob


Nov 16 '05 #3
"William Stacey [MVP]" <st***********@mvps.org> wrote in message news:<eV*************@TK2MSFTNGP11.phx.gbl>...
IIRC, to get it to work, just using "myDelegate();" to run the delegate.

--
William Stacey
MVP Directory Services
http://mvp.support.microsoft.com


William,

I know how to invoke a delegate, I was only wondering about the reason
for the behaviour I described in my post.
Bob
Nov 16 '05 #4

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

Similar topics

1
by: boxim | last post by:
hi all, I'm having a few problems whereby my application is hanging when using the Invoke method of a form's control. Basically, when a user clicks a button on the form, it calls a remote...
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...
0
by: Alan | last post by:
Hi all, Before the invoke list of one delegate is called, is thers one general method to go inside the procedure in order to make some changes such as removing some delegates from the list. If so,...
2
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...
4
by: Beren | last post by:
Hello I'm trying to use Cache expiration and its callback feature to easily add automated tasks programmatically. The task should be run when the Cache object expired The problem I'm facing...
4
by: Charles Law | last post by:
Hi guys. I have two threads: a main thread and a background thread. Lots of stuff happens in the background thread that means I have to update several (lots) of controls on a form. It is...
9
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...
2
by: waylonflinn | last post by:
I'm looking for a way to invoke methods with an arbitrary number of parameters of arbitrary type from within a single method, when those parameters are known at the time of invocation of the...
6
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,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.