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

Event-Event calling

Is it good programming practice to call an event within an event?
I'm I creating recursion somehow somewhere? Does an event (e.g. send, e)
ever end?

I'm sorry, I'm not sure I know what I mean, however, I do know what ever it
is I should be aware of it.

currentcell_event(..)
{
..
..
moveLastGridcell_button(sender, e);
}

Steve

Nov 16 '05 #1
6 1743
Technically, you can't raise an event from within an event... events
aren't language constructs. You can, however, raise an event from
within an event _handler_, and there's nothing wrong with that. Anyway,
that's quibbling, isn't it?

Is there anything wrong with raising an event from within an event
handler? No, there's nothing wrong with it at all. Just like
exceptions, you may want to transform events into other events. For
example, I wrote a bunch of Binding classes for use in my Windows
forms: they connect properties in my model class to controls on my
form. One of the kinds of binding that I created is an AndBinding. The
AndBinding subscribes to two xxxChanged events of my model, each
corresponding to a boolean property of the model. Whenever one of these
two properties changes, the model raises the xxxChanged event. If the
AndBinding finds that this makes the result of an "and" on the two
properties change its value, it in turn raises a "ValueChanged" event,
right from inside the event handler. In other words, it handles an
event from one object and then transforms that event into a different
event to be consumed by some other object.

Of course, if you create circular chains of events then your program
will die with a stack overflow when that event is raised (event
dispatch is just a method call, after all).

As well, there are some stylstic concerns. If you have lots of code
raising events from within event handlers then maybe you're trying to
pack too many smarts into your presentation code and need to take a
look at the Model-View-Controller software pattern. It's not
syntactically evil... it's just that if grows too much it can be
difficult to figure out what's going on.

Nov 16 '05 #2
The primary reason that it isn't good to use events as a mechanism for
handling normal logic, is that events cost considerably more than simple
object calls.

Use events for error handling, never for logic that can be detected and
handled in another way.

In addition, there are many design patterns that will allow you to use a
flexible design that often sidesteps the need for event handlers to throw
custom events. Check out the Chain of Responsibility and the Command
patterns.

--- Nick

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
Is it good programming practice to call an event within an event?
I'm I creating recursion somehow somewhere? Does an event (e.g. send, e)
ever end?

I'm sorry, I'm not sure I know what I mean, however, I do know what ever it is I should be aware of it.

currentcell_event(..)
{
.
.
moveLastGridcell_button(sender, e);
}

Steve

Nov 16 '05 #3
Thank you for both your comments. Based on your comments I think it's best if
I avoid the pratice, put the code in my interface and implement some of Mr.
Gamma's patterns

Thank you again --Steve

"Nick Malik" wrote:
The primary reason that it isn't good to use events as a mechanism for
handling normal logic, is that events cost considerably more than simple
object calls.

Use events for error handling, never for logic that can be detected and
handled in another way.

In addition, there are many design patterns that will allow you to use a
flexible design that often sidesteps the need for event handlers to throw
custom events. Check out the Chain of Responsibility and the Command
patterns.

--- Nick

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
Is it good programming practice to call an event within an event?
I'm I creating recursion somehow somewhere? Does an event (e.g. send, e)
ever end?

I'm sorry, I'm not sure I know what I mean, however, I do know what ever

it
is I should be aware of it.

currentcell_event(..)
{
.
.
moveLastGridcell_button(sender, e);
}

Steve


Nov 16 '05 #4
I'm no guru, but I think that you're confusing events with exceptions.

Events don't cost considerably more than simple object calls. Raising
an event is a little bit more expensive than a simple method call
(there's a test for null, an for multicast events there is a walk down
a subscriber list). It's exceptions that introduce overhead and are
considerably more expensive than a method call.

The next statement, "Use events for error handling, never for logic
that can be detected and handled in another way," is what set me to
thinking that perhaps you're confusing events and exceptions. The
entire WinForms object model runs on events. ADO.NET makes heavy use of
events. The Model-View-Controller design pattern that I mentioned
explicitly calls on the programmer to _prefer_ events over using simple
method calls because it vastly simplifies the application (in those
cases in which the design pattern applies).

It's exceptions that you shouldn't use for normal program flow.
Exceptions and try...catch are universally acknowledged as costly and
best avoided when it's not unreasonable to do so.

The only problem I've ever had with using events was that of
unknowingly creating circular chains of events that caused my apps to
hang, which is why I went to Model-View-Controller design, because that
design clearly lays out the responsibilities of each software component
and avoids the kind of event chaos that frequently results from
grow-your-own event architectures.

Nov 16 '05 #5
Thanks Bruce

I've changed my ADO code to something like below. Circular chains was
exactly what I was afraid of before

Thank You
Steve

mycell1_event(..)
{
event ("mycell1");
}

mycell2_event(..)
{
event ("mycell2);
}

event (string cell)
{
if(cell == mycell1)
..
..
..
}
"Bruce Wood" wrote:
I'm no guru, but I think that you're confusing events with exceptions.

Events don't cost considerably more than simple object calls. Raising
an event is a little bit more expensive than a simple method call
(there's a test for null, an for multicast events there is a walk down
a subscriber list). It's exceptions that introduce overhead and are
considerably more expensive than a method call.

The next statement, "Use events for error handling, never for logic
that can be detected and handled in another way," is what set me to
thinking that perhaps you're confusing events and exceptions. The
entire WinForms object model runs on events. ADO.NET makes heavy use of
events. The Model-View-Controller design pattern that I mentioned
explicitly calls on the programmer to _prefer_ events over using simple
method calls because it vastly simplifies the application (in those
cases in which the design pattern applies).

It's exceptions that you shouldn't use for normal program flow.
Exceptions and try...catch are universally acknowledged as costly and
best avoided when it's not unreasonable to do so.

The only problem I've ever had with using events was that of
unknowingly creating circular chains of events that caused my apps to
hang, which is why I went to Model-View-Controller design, because that
design clearly lays out the responsibilities of each software component
and avoids the kind of event chaos that frequently results from
grow-your-own event architectures.

Nov 16 '05 #6
Hi Bruce,

I was having a less than productive moment when I wrote my original reply.
While the OP was clearly referring to events, in my mind I thought he was
referring to exceptions and went off on a completely wild tangent. I should
have read the original message more carefully before responding.

Thanks for correcting my goof.

--- Nick

"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I'm no guru, but I think that you're confusing events with exceptions.

Events don't cost considerably more than simple object calls. Raising
an event is a little bit more expensive than a simple method call
(there's a test for null, an for multicast events there is a walk down
a subscriber list). It's exceptions that introduce overhead and are
considerably more expensive than a method call.

The next statement, "Use events for error handling, never for logic
that can be detected and handled in another way," is what set me to
thinking that perhaps you're confusing events and exceptions. The
entire WinForms object model runs on events. ADO.NET makes heavy use of
events. The Model-View-Controller design pattern that I mentioned
explicitly calls on the programmer to _prefer_ events over using simple
method calls because it vastly simplifies the application (in those
cases in which the design pattern applies).

It's exceptions that you shouldn't use for normal program flow.
Exceptions and try...catch are universally acknowledged as costly and
best avoided when it's not unreasonable to do so.

The only problem I've ever had with using events was that of
unknowingly creating circular chains of events that caused my apps to
hang, which is why I went to Model-View-Controller design, because that
design clearly lays out the responsibilities of each software component
and avoids the kind of event chaos that frequently results from
grow-your-own event architectures.

Nov 16 '05 #7

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

Similar topics

1
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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...

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.