calling event handler twice

  • Thread starter Thread starter harmeet
  • Start date Start date
H

harmeet

hi all,

i am implementing command pattern in my project and adding event handler for
tollbar buttonclick event. while i click on any button it notify multiple
times due to multiple event handler associated with it.
now i want to avoid duplicate event handler addition while adding handler
using AddHandler Keyword in VB.NET.

please help me out to resolve this problem.

thanks in advance

Regards
Harmeet
 
Without knowing your application, I cannot give exact guidance. Here are a
few things to think about.

* Unless you unwire events, event handlers will fire. To avoid unnecessary
firing of event handlers, do not implement any handlers you do not need. As
VB.NET uses the Handles keyword, you have the ability to turn this off rather
quickly.

* Multiple events can easily be fired, by default settings, as events bubble
up. You can turn this off, if it makes sense to you. This is a major source
of multiple events being fired up the chain.

* As much as possible, try to stick with the default workings of .NET. In
cases where this does not fit, you can certainly code your own event handler
mechanism, but, as a rule, I would stick to what you are provided if it fits
your needs. I see too many people trying to rework the system when it is
unnecessary.

* When you architect, pay attention to the chain of events that are going to
be handled. You may find that a simple rearchitecture gets you away from the
issues you are having.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
harmeet said:
i am implementing command pattern in my project and adding event
handler for tollbar buttonclick event. while i click on any button it
notify multiple times due to multiple event handler associated with
it.
now i want to avoid duplicate event handler addition while adding
handler using AddHandler Keyword in VB.NET.

If you use AddHandler make sure that the component does not have
WithEvents. You should use one or the other, not both.

Richard
 
Back
Top