473,778 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 AlarmEventHandl er(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(AlarmEv entArgs 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 3012
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 AlarmEventHandl er(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(AlarmEv entArgs 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**********@s pammotel.com> wrote in message news:<#h******* *******@TK2MSFT NGP12.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
2108
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 form and I can process what I want based on them. If I try to catch raised events by this class but within a form located in a different assembly, I am not able to
6
2883
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 TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
4
17270
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 maintain the reference to any module.
7
2444
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 Manager. Your main application then hooks into the Plugin Manager. What I'm trying to figure out is how to impliment some form of raising
0
1724
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 upto a hundred user controls on a single page and AutoPostBack isn't an option. I have no problem with raising events when an user control is dropped on the aspx page.
0
1453
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 (0x80041003): Exception from HRESULT: 0x80041003. at Microsoft.EnterpriseInstrumentation.EventSinks.WmiEventSink ..Write(Object eventToRaise) at
4
1598
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 the way my component raises events to follow the Framework Design Guides verbatim; ie (object sender, EventArgs (or some subclass there of) e). The thing that was not explained is why should I need to cast the sender to 'object' when I know...
2
1697
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 the parent form. This is fine. The problem occurs when I want to raise an event for a user clicking on one of the clsRecords which are on the grid. So I've placed: Public Event GridRecordClicked(ByVal rec As clsGridRecord,
0
1259
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 events work everytime. When the container is Internet Explorer, raising the events work on some PCs, but generate the exception: "object does not match target type" on some other PCs.
7
2873
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 in the label. I tried by raising events as used in Winforms but it is not as easy as
0
9628
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
10292
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, 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...
0
9923
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...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
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
5368
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...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
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.