473,382 Members | 1,387 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,382 software developers and data experts.

Raising a set of events

Hi,

We can raise an event by calling some method the same
like a delegate. Actually one event can reference a few
different method each of these meets delegate declaration.

Like below:
(...)
clock.Alarm += new AlarmEventHandler(w.AlarmRang);
(...)
where clock.Alarm is an event.

My question is woh can I only in one step call all of
these event handlers, like below:
(...)
protected virtual void OnAlarm(AlarmEventArgs e)
{
if (Alarm != null)
{
// Invokes the delegates.
Alarm(this, e);
}
}
(...)
By calling Alarm(this, e), we actually calling all
handlers.

For me it's a little strange, I think in this way we can
call only last referenced handler. So, I'm used to think
in C++ (pointers) way.

Regards
Krzysztof
Nov 15 '05 #1
2 2990
Think of a delegate as a collection of pointers that you can both add to
(using +=) or remove from (using -=). When you call it, it just goes through
all of the pointers in its collection and calls them with the parameters
supplied

Greg
"Krzysztof Malinowski" <km******@toya.net.pl> wrote in message
news:05****************************@phx.gbl...
Hi,

We can raise an event by calling some method the same
like a delegate. Actually one event can reference a few
different method each of these meets delegate declaration.

Like below:
(...)
clock.Alarm += new AlarmEventHandler(w.AlarmRang);
(...)
where clock.Alarm is an event.

My question is woh can I only in one step call all of
these event handlers, like below:
(...)
protected virtual void OnAlarm(AlarmEventArgs e)
{
if (Alarm != null)
{
// Invokes the delegates.
Alarm(this, e);
}
}
(...)
By calling Alarm(this, e), we actually calling all
handlers.

For me it's a little strange, I think in this way we can
call only last referenced handler. So, I'm used to think
in C++ (pointers) way.

Regards
Krzysztof

Nov 15 '05 #2
And IF you want to manage it yourself, you could add a collection
(probably a hashtable) to your explictly designed delegate class and
have that class hold references to all the registered event consumers
in that hashtable. Then when an event fires, you spin thru' your
hashtable and fire the events on X-number of clients. This works best
when you have your clients implement a known interface.

"Greg Bacchus" <FB**********@spammotel.com> wrote in message news:<#h**************@TK2MSFTNGP12.phx.gbl>...
Think of a delegate as a collection of pointers that you can both add to
(using +=) or remove from (using -=). When you call it, it just goes through
all of the pointers in its collection and calls them with the parameters
supplied

Greg

Nov 15 '05 #3

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

Similar topics

4
by: serge calderara | last post by:
Dear all, I have a class wich is raising events as normally it should do. having a form in the same assembly wich is catching those events works fne. Raise events gets catch normaly within the...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
7
by: cider123 | last post by:
I'm coding a project using the following article as reference: http://www.codeproject.com/csharp/DynamicPluginManager.asp In this type of project, plugins are loaded dynamically into a Plugin...
0
by: Greg Park | last post by:
I have many user controls loading into a web page using Page.LoadControl However, I'm unable to figure out how to raise an event when a button is click or a check box is checked. I can have...
0
by: Joe Campbell | last post by:
I am encountering a problem raising WMI events from an asp.net application. The error received (as captured in the event log) is as follows: System.Runtime.InteropServices.COMException...
4
by: Dave A | last post by:
I am developing a somewhat complex component at the moment and coincidently I am also reading the Framework Design Guidelines book. After reading the section about event raising I have re-written...
2
by: Gman | last post by:
Hi, I have created a usercontrol, a grid control essentially. Within it I have a class: clsGridRecord. I have coded the events such that when a user clicks on the grid, say, the events occur on...
0
by: Apu Nahasapeemapetilon | last post by:
Suggestions on cross-posting this issue would be appreciated. I've got a C# .NET DLL (CLR v1.1) that raises events into its container. When the container is a .NET application, raising the...
7
by: Christian Cambier | last post by:
Hi, I have a textbox in a web user control. I then add the usercontrol to a web form. I also add a label in the web form. Now, when I press a key in the textbox, i want to display some text...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.