473,394 Members | 1,794 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,394 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 2991
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
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...

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.