Are multiple events expensive?

B

Bob

Hi,
I have a newbie question on event listening. I have a form that is
monitoring progress in an application. The application consists of
many classes, multithreaded, etc. The form listens for events on the
main executing class, which in turn listens for events on classes it
uses, etc, so that an event might have to propagate through several
layers of event listeners and new events to make its way back to the
form. I am wondering whether this is computationally expensive (ie
raising multiple events) or if it is an ok way to program?

Thanks,
Bob
 
A

Alberto Poblacion

Bob said:
I have a newbie question on event listening. I have a form that is
monitoring progress in an application. The application consists of
many classes, multithreaded, etc. The form listens for events on the
main executing class, which in turn listens for events on classes it
uses, etc, so that an event might have to propagate through several
layers of event listeners and new events to make its way back to the
form. I am wondering whether this is computationally expensive (ie
raising multiple events) or if it is an ok way to program?

Listening for an event does not have any cost, that is, nothing happens
until the event is fired. When the events are raised, the cost is roughly
equivalent to method calls (imagine that instead of using an event that
raises another event you had a method that called another method, and so
on).
 
B

Bob

Listening for an event does not have any cost, that is, nothing happens
until the event is fired. When the events are raised, the cost is roughly
equivalent to method calls (imagine that instead of using an event that
raises another event you had a method that called another method, and so
on).

Great, thanks!
 
J

Jon Davis

Event delegate assignments take up some memory, as delegates themselves and
the containment of them in an event subscription stack aren't free, but a
handful of delegate assignments won't matter.

As Alberto mentioned, the performance hit is on the delegates' executions.
There, the impact is more or less measurable by how often your event
handlers are executed and what exactly they do.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top