473,729 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the difference between event and multicast delegate

Hi,
I have a conceptual question on Events and Multicast Delegates. Let me
explain:

As we know an event is a multicast delegate. What we declare as an
event is inherently a multicast delegate. I really do not undrestand
what additional features the "event" keyword adds to multicast
delegate. The only thing that I see as an additional feature is a
"Thunder Icon" near event name in VS IDE when intellisense works;).

Can anybody clarify this matter for me?
Sep 17 '08 #1
5 8923
I believe event is derived from multicast delegate and not he other way
around. If I understand it correct, event is a C# keyword that shortcuts the
creation of a mutlicast delegate (or perhaps it would be better to say "a
particular type of multicast delegate"). It is not a superclass for
multicast delegate.

The thunder icon is a feature of the IDE and does not affect the underlying
classes. It is designed to make it easier for you to find your events.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

*************** *************** **************
| Think outside the box! |
*************** *************** **************
"AliRezaGoo gle" <as*******@yaho o.comwrote in message
news:96******** *************** ***********@l42 g2000hsc.google groups.com...
Hi,
I have a conceptual question on Events and Multicast Delegates. Let me
explain:

As we know an event is a multicast delegate. What we declare as an
event is inherently a multicast delegate. I really do not undrestand
what additional features the "event" keyword adds to multicast
delegate. The only thing that I see as an additional feature is a
"Thunder Icon" near event name in VS IDE when intellisense works;).

Can anybody clarify this matter for me?
Sep 17 '08 #2
AliRezaGoogle <as*******@yaho o.comwrote:
I have a conceptual question on Events and Multicast Delegates. Let me
explain:

As we know an event is a multicast delegate.
No it's not. It's a pair of methods - add and remove, or subscribe and
unsubscribe.

See http://pobox.com/~skeet/csharp/events.html for a great deal more
info on this.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 17 '08 #3
As we know an event is a multicast delegate.

No; an event is defined as a set of accessor methods that encapsulate
a delegate in the same way as a property encapsulates a regular field.
Where a property defined "get" and "set", an event defines "add" and
"remove". That is all an event is. This provides the same abstraction
as properties, and formalizes the contract: you can subscribe and
unsubscribe, but you don't have direct control of the delegate.

In particular, this prevents 2 unwanted scenarios:

a: obj.SomeEvent = SomeHandler;
(damn, what happened to the other subscribers?)

b: obj.SomeEvent(. ..)
(only "obj" should be invoking the event - not external callers)

It also allows for abstraction in terms of how the delegate is stored.
A good example of this is windows forms; they have lots of events,
which most of the time aren't subscribed. Having a delegate field per
event would be expensive, so instead an EventHandlerLis t is used to
store sparse subscriptions efficiently. You could also (for example)
do other processing when adding/removing subscribers: check access,
facade to another property, lazy loading, etc.

Marc

Sep 17 '08 #4
Thanks a lot John. I followed your link and the article clarified
everything for me. Many thanks man.

Jon Skeet [ C# MVP ] wrote:
AliRezaGoogle <as*******@yaho o.comwrote:
I have a conceptual question on Events and Multicast Delegates. Let me
explain:

As we know an event is a multicast delegate.

No it's not. It's a pair of methods - add and remove, or subscribe and
unsubscribe.

See http://pobox.com/~skeet/csharp/events.html for a great deal more
info on this.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 18 '08 #5

Thanks a lot Marc. You are right in this point. Many thanks for your
help.

Marc Gravell wrote:
As we know an event is a multicast delegate.

No; an event is defined as a set of accessor methods that encapsulate
a delegate in the same way as a property encapsulates a regular field.
Where a property defined "get" and "set", an event defines "add" and
"remove". That is all an event is. This provides the same abstraction
as properties, and formalizes the contract: you can subscribe and
unsubscribe, but you don't have direct control of the delegate.

In particular, this prevents 2 unwanted scenarios:

a: obj.SomeEvent = SomeHandler;
(damn, what happened to the other subscribers?)

b: obj.SomeEvent(. ..)
(only "obj" should be invoking the event - not external callers)

It also allows for abstraction in terms of how the delegate is stored.
A good example of this is windows forms; they have lots of events,
which most of the time aren't subscribed. Having a delegate field per
event would be expensive, so instead an EventHandlerLis t is used to
store sparse subscriptions efficiently. You could also (for example)
do other processing when adding/removing subscribers: check access,
facade to another property, lazy loading, etc.

Marc
Sep 18 '08 #6

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

Similar topics

9
2457
by: Jay | last post by:
Everywhere I go (read/browse) I see these parameters.... ByVal sender As Object, ByVal e As System.EventArgs Yet I never see them used within the function/method. Could someone tell me what they mean/do please. JP
7
1688
by: Schorschi | last post by:
I know there is a way to do this, but I don't know how. Via a custom event? I have some code that I only want to run during a paint event. I could build a form instance that has the code and inherit it in all my other forms, but a simple event link? if that is the right term would be easier? Thx.
27
1945
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the <Serialized()> attribute on the class and away you go. As Homer would say - "D'Oh" The root of my problem lies in the way VB implements Events and the fact that you can't apply the <NonSerialized> attribute to the little rascals.
1
3600
by: Lore Leunoeg | last post by:
Hello again. My code adds several EventHandlers to the same Event-Delegate. Thereafter I 'd like to get a list of all the handlers added. I found that events are some kind of multicast delegates and that it should be possible to get the list with den GetInvocationList-Method of the Delegate. But I really don't succeed to do this. ClickButton is the class that holds the delegate and the event (ClickEvent) and fires the event.
9
2368
by: DrBonzo | last post by:
Is there any effective difference between doing something in the DragDrop event handler and doing it in the OnDragDrop(.) method of a control? I'm coming from a MFC background and am having a hard time comprehending the difference. Thanks for your explanations . . .
14
25268
by: DaTurk | last post by:
I am makeing a Multicast server client setup and was wondering what the difference is between Socket.Connect, and Socket.Bind. It may be a stupid question, but I was just curious. Because I tried a test, and I can't bind two sockets to the same port/ip but I can connect with one socket, and bind with another to the same ip/port. Thanks
9
3191
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will load with different data (locations, departments, etc.).
6
3790
by: =?Utf-8?B?TWlrZVo=?= | last post by:
I have a thread that parser video-frame from network streaming. It can get up to 1000 frame/second. I want another thread to process video-frame. I can use RaiseEvent or Callback Function. My question is: 1) Which way is more efficiency? Event or Callback function. 2) Does <Eventrun on Main Window thread? This is a windows application. All form controls event run on main form thread. Thanks
4
2881
by: bjjnova | last post by:
I need help dynamically resetting an event handler. I have a form with several buttons. I have intialized the Click event of a particular button thus on the form: _button_3.Click += new EventHandler(the_controller.onButton3Click_NewEE); On the same form, I am establishing a property so that I can reset the Click event from another class (first part of my question: how do I
0
8761
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,...
0
9281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
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,...
0
8148
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
6722
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
6022
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();...
1
3238
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
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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.