Events are not only used in the UI layer, but everywhere where feedback
needs to be provided.
Events provide a way for the object to call back to the main code and
indicates that something has happen where action might need to be taken.
Let's look at things from a human perspective. Suppose that you have a dam
holding back water. You want to make sure that the dam does not break under
pressure. Well, the operator could look at the instrumentation every minute
and compare the value with the expected pressure, but the operator probably
has better things to do. And besides, how often would the operator look at
the instruments -- every minute, or 30 seconds, or sooner.
Now, if the dam was event driven, the dam could have sensors located across
its surface. These sensors would monitor the pressure. If the pressure
gets too high, the sensors will send a signal back to the operator and maybe
flash a light and sound an alert. This will get the operators attention so
the person can open the gates.
The operator looking at the console would be like a program running through
a look or using a thread that wakes periodically. Instead of that, let's
turn the sensors into events. When an event determines the pressure is too
high (PressureOutOfBounds event), the event will create an event delegate
(PressureOutOfBoundsEventHandler delegate) that points to a method that will
sound an alert on the console. The handler receives some parameters
(PressureOutOfBoundsEventArgs) which might contain information like the
current pressure.
"DKode" <dk****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hello,
I have a question about delegates and events
I have a basic understanding of each, but in the apps I'm building I'm
never needing to use these tools. I'm wondering when and where you
should use these features. I am assuming that they are used in your
presentation layer but perhaps I am sorely wrong.
thank you
Sean