473,765 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Alternative Ways To Implement "Events"

Just looking to compile a list of "all the ways to implement events".

I'm NOT looking to get into the merits or mechanics of each in this
thread... just want to identify them all - good, bad, and ugly.

Here's what I have so far
1. Implement via the 'event' keyword (with associated delegate, etc)

2. Expose a private delegate via a public property (really a "roll yer own"
version of the 'event' keyword method).

3. Old-school callbacks in which one object (objA) calls another (objB),
passing a reference of itself to the called object (objB then contains a
reference to objA). The called object can then call methods on the calling
object (i.e., objB calls methods of objA).

4 ... ???

I'd appreciate any additional ways to implement "events" - including total
hacks.

I'm looking to grasp finally grasp the entire landscape of events and
callback mechanisms that are available in .NET (even if they are independent
of .NET, like plain ole' callbacks).

Thanks.
Aug 9 '07 #1
6 4810
Smithers,

Technically, you have to use the "event" keyword when you want to have
an event on your type. This is baked into the metadata (and shown through
Reflection) as an event. All the methods, besides #1, are not events,
technically.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Smithers" <A@B.comwrote in message
news:uh******** ******@TK2MSFTN GP03.phx.gbl...
Just looking to compile a list of "all the ways to implement events".

I'm NOT looking to get into the merits or mechanics of each in this
thread... just want to identify them all - good, bad, and ugly.

Here's what I have so far
1. Implement via the 'event' keyword (with associated delegate, etc)

2. Expose a private delegate via a public property (really a "roll yer
own" version of the 'event' keyword method).

3. Old-school callbacks in which one object (objA) calls another (objB),
passing a reference of itself to the called object (objB then contains a
reference to objA). The called object can then call methods on the calling
object (i.e., objB calls methods of objA).

4 ... ???

I'd appreciate any additional ways to implement "events" - including total
hacks.

I'm looking to grasp finally grasp the entire landscape of events and
callback mechanisms that are available in .NET (even if they are
independent of .NET, like plain ole' callbacks).

Thanks.

Aug 9 '07 #2

In some places .NET uses attributes to subscribe event handlers. Look
at OnSerializingAt tribute and related attributes (there's 4 of them).

Java (at least as of 1.4, not sure if it changed), implements events
using interfaces. Instead of declaring an event like in C# each event
type has an interface and there are methods for subsribing to an
"event" by providing an interface implementation. Then inner classes,
especially anonymous inner classes, are heavily used as "event"
handlers. I probably have some details wrong but I'm pretty sure on
the basic principle.

DOM (JavaScript, ActionScript) implements events using name events and
function references (delegates). I've actually seen people implement
custom events in .NET this way, but in that situation we turned down
the contract because of that odd requirement.
And to be perfectly clear, I'm not advocating or condoning the use of
any of these methods over the standard way to create events in .NET..
just you asked for everything. :-)

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Thu, 9 Aug 2007 13:26:09 -0700, "Smithers" <A@B.comwrote :
>Just looking to compile a list of "all the ways to implement events".

I'm NOT looking to get into the merits or mechanics of each in this
thread... just want to identify them all - good, bad, and ugly.

Here's what I have so far
1. Implement via the 'event' keyword (with associated delegate, etc)

2. Expose a private delegate via a public property (really a "roll yer own"
version of the 'event' keyword method).

3. Old-school callbacks in which one object (objA) calls another (objB),
passing a reference of itself to the called object (objB then contains a
reference to objA). The called object can then call methods on the calling
object (i.e., objB calls methods of objA).

4 ... ???

I'd appreciate any additional ways to implement "events" - including total
hacks.

I'm looking to grasp finally grasp the entire landscape of events and
callback mechanisms that are available in .NET (even if they are independent
of .NET, like plain ole' callbacks).

Thanks.
Aug 9 '07 #3
<snip>

<< While loosely, it is an event, the serialization engine uses reflection
to call the method >>>

<snip>

Nicholas,

Please note that the answer that Samuel provided is *exactly* the sort of
response I was looking for in my OP.

Please note that the OP subject has the word, events, in quotes ("events")
which indicates that I'm looking not only for events, but also anything that
can be roughly construed as an event. I went on in the body of the OP to
continue the use of quotes, and even explicitly requiested "total hacks"
(meaning not prim and proper events).

Please do not discourage folks from responding simply because they aren't
providing some way to implement events according to some narrow technically
specific definition. If thats' what I wanted, the OP wouldn't have described
my intent as going after the "entire landscape" of events and callback
mechanisms.... even those that are independent of .NET."

-S
Aug 9 '07 #4
Samuel,

The OnSerializingAt tribute does not subscribe the method to an event.
While loosely, it is an event, the serialization engine uses reflection to
call the method.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Samuel R. Neff" <sa********@nom ail.comwrote in message
news:sp******** *************** *********@4ax.c om...
>
In some places .NET uses attributes to subscribe event handlers. Look
at OnSerializingAt tribute and related attributes (there's 4 of them).

Java (at least as of 1.4, not sure if it changed), implements events
using interfaces. Instead of declaring an event like in C# each event
type has an interface and there are methods for subsribing to an
"event" by providing an interface implementation. Then inner classes,
especially anonymous inner classes, are heavily used as "event"
handlers. I probably have some details wrong but I'm pretty sure on
the basic principle.

DOM (JavaScript, ActionScript) implements events using name events and
function references (delegates). I've actually seen people implement
custom events in .NET this way, but in that situation we turned down
the contract because of that odd requirement.
And to be perfectly clear, I'm not advocating or condoning the use of
any of these methods over the standard way to create events in .NET..
just you asked for everything. :-)

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Thu, 9 Aug 2007 13:26:09 -0700, "Smithers" <A@B.comwrote :
>>Just looking to compile a list of "all the ways to implement events".

I'm NOT looking to get into the merits or mechanics of each in this
thread... just want to identify them all - good, bad, and ugly.

Here's what I have so far
1. Implement via the 'event' keyword (with associated delegate, etc)

2. Expose a private delegate via a public property (really a "roll yer
own"
version of the 'event' keyword method).

3. Old-school callbacks in which one object (objA) calls another (objB),
passing a reference of itself to the called object (objB then contains a
reference to objA). The called object can then call methods on the calling
object (i.e., objB calls methods of objA).

4 ... ???

I'd appreciate any additional ways to implement "events" - including total
hacks.

I'm looking to grasp finally grasp the entire landscape of events and
callback mechanisms that are available in .NET (even if they are
independent
of .NET, like plain ole' callbacks).

Thanks.

Aug 9 '07 #5
I'm not trying to discourage people from answering, but I don't want to
spread the wrong impression about what an event is in .NET. It has a very
concrete definition (reflected by the metadata reflected on the type, and
reflected through the EventInfo type in the System.Reflecti on namespace).

To be frank, the question that you asked has a vast number of answers.
You are basically looking for anything that can signal your code in response
to an action. The number of mechanisms for this is pretty huge.

Some are more common than others, granted, and I feel you have hit on
all of the common ones, I believe, but there are many more to be had
(depending on the scenario and context).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Smithers" <A@B.comwrote in message
news:OR******** ******@TK2MSFTN GP04.phx.gbl...
<snip>

<< While loosely, it is an event, the serialization engine uses reflection
to call the method >>>

<snip>

Nicholas,

Please note that the answer that Samuel provided is *exactly* the sort of
response I was looking for in my OP.

Please note that the OP subject has the word, events, in quotes ("events")
which indicates that I'm looking not only for events, but also anything
that can be roughly construed as an event. I went on in the body of the OP
to continue the use of quotes, and even explicitly requiested "total
hacks" (meaning not prim and proper events).

Please do not discourage folks from responding simply because they aren't
providing some way to implement events according to some narrow
technically specific definition. If thats' what I wanted, the OP wouldn't
have described my intent as going after the "entire landscape" of events
and callback mechanisms.... even those that are independent of .NET."

-S
Aug 10 '07 #6

And since I guess you missed this part of my original post, I'll
repeat..

"
And to be perfectly clear, I'm not advocating or condoning the use of
any of these methods over the standard way to create events in .NET..
just you asked for everything. :-)
"

While this may seem like a silly question, silly questions come up a
lot (especially in consulting contracts, which I'm glad we no longer
have to deal with) and it's always good to be knowledgeable about the
subject and know lots of ways to do things, even if you'd never
actually use them 'cause there is an accepted best practice (and of
course best practices do change over time, for example events are
different in plain .NET and WPF--although WPF events are based and a
wrapper of .NET events).

btw, Smithers, that's another one to add to your list. WPF supports
tunneling and bubbling of events. I'm not the most qualified to
explain it, but it's a very nice extension to .NET events.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Thu, 9 Aug 2007 21:40:58 -0400, "Nicholas Paldino [.NET/C# MVP]"
<mv*@spam.guard .caspershouse.c omwrote:
I'm not trying to discourage people from answering, but I don't want to
spread the wrong impression about what an event is in .NET. It has a very
concrete definition (reflected by the metadata reflected on the type, and
reflected through the EventInfo type in the System.Reflecti on namespace).

To be frank, the question that you asked has a vast number of answers.
You are basically looking for anything that can signal your code in response
to an action. The number of mechanisms for this is pretty huge.

Some are more common than others, granted, and I feel you have hit on
all of the common ones, I believe, but there are many more to be had
(depending on the scenario and context).
Aug 10 '07 #7

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

Similar topics

6
37220
by: Lauren Wilson | last post by:
Hello group, Somehow, I have not yet fully understood the meaning and purpose of "DoEvents". Can someone post or point me to a clear, concise explanation of it -- one that includes situational examples of how and why it is used? The Access on-line help is not as helpful as I need for my mental density! Sorry to be so dense. Please indulge me.
0
1404
by: Robin Tucker | last post by:
Hi people, Is it possible for me to handle events raised by an object which is embeded in a web browser control, from my VB.NET code? I am able to gain access to the object itself through the browser object model and have successfully used IPersistStorage to get/set the object in the browser control from VB.NET. As the object is "in place active" in the browser (I'm using the browser as an OLE container), I would like to be notified of...
2
2110
by: Jonathan | last post by:
Hi I need implement loosely coupled events to raise events in a Classibrary project from one Windows Application project, and hanlde these from other Windows Application project. I found this article in MSDN, but I don't know how to implement. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconlooselycoupledevents.asp Thanks :)
3
5174
by: Robert Inder | last post by:
I am struggling to catch kestrokes within an Internet Explorer 6 window. My window happens to be displaying three frames, though I suspect a similar problem would arise with a single document. The "<body.." tag in each frame includes an "onKeyPress" handler to catch and act on key presses. And if I focus the window by clicking on the content of one of the documents, keystrokes are sent to the handler on its "<body..." tag.
3
2569
by: Anil Gupte | last post by:
I want to embed using an embed tag or object tag (like YouTube or others do) to embed a video file in a web page. I want to know if there is an event related to the video being done playing. Also are there other events? Thanx in advance, -- Anil Gupte www.keeninc.net www.icinema.com
0
1203
by: murtyin | last post by:
Hi to All, I created one ClassLibrary in .Net using VB.Net, which is configured for COM InterOP. In this Library, I created 3 classes and below they are. (1) Document class: which is having 2 properties (a) AddPage : function for adding a Page to the Document. (b) DrawToFile : method which 'll draw the output to the specified file. (2) Page class: Having a AddLabel function used for adding a Label to the Page. (3) Label...
5
2400
by: raylopez99 | last post by:
I understand delegates (static and non-static) and I agree they are very useful, and that the "Forms" used in the Windows .NET API could not work without them. That said, I'm curious as to how many heavy duty pro programmers in this newsgroup have actually used a delegate in their code, say in the last year of coding. By "use" I mean constructed a delegate and using it in an Event Source class and an Event Receiver class. Interfaces...
0
1369
by: miarfej | last post by:
Hi to all.. i am just new here, hoping to find some suggestions. I am writing a code in VC++. It is about creating an activeX control using MFC. This control exposes the properties and methods of another (hidden, we may say) activeX control using IDispatch implementations (GetIDsOfNames, and Invoke). I have no problem with these things. My problem is that, I need also to expose the events of the hidden activeX control. That is, my custom...
5
2084
by: phub11 | last post by:
Hi all, I have some onmousedown and onmouseup events that dynamically insert buttons (and input text fields) into a table. However, when I click on one of the buttons (or enter text into one of the boxes) the onmouseup and onmousedown events are no longer responsive. Any ideas on what happening? Thanks!
0
9398
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
10156
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
10007
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...
0
9832
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...
1
7375
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
5275
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...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
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.