Can I stop other event handlers from receiving an event?

G

Guest

If i add an event handler to a particular event on a Control, can I consume
events that are triggered so any other handlers registered to the same event
do not process their code?
 
K

Kumar Reddi

Yeah, When you are attaching an event handler to an event, you use "+="
syntax, this adds to the list of handlers, if you simply use "=", that is
the only event handler that can recieve the event
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Kamur,

In the case of events += -= are translated by the compiler into calls to add
and remove event accessors. Using = with events on the other hand makes the
compiler t ogenerate an error message. Using = operator is possible when it
goes for variables of some delegate type, but not for events.

To answer to the original poster.... No, it is not possible. Even if it was
you cannot know how many handlers has been already registered, so to cancel
the handlers invokation won't lead to any good.
 
K

Kumar Reddi

Hi Goutsev,
You are right. My mistake. Was not thinking when I typed the response

Kumar
Stoitcho Goutsev \(100\) said:
Hi Kamur,

In the case of events += -= are translated by the compiler into calls to add
and remove event accessors. Using = with events on the other hand makes the
compiler t ogenerate an error message. Using = operator is possible when it
goes for variables of some delegate type, but not for events.

To answer to the original poster.... No, it is not possible. Even if it was
you cannot know how many handlers has been already registered, so to cancel
the handlers invokation won't lead to any good.


--
Stoitcho Goutsev (100) [C# MVP]

Kumar Reddi said:
Yeah, When you are attaching an event handler to an event, you use "+="
syntax, this adds to the list of handlers, if you simply use "=", that is
the only event handler that can recieve the event
 

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