How do I make sure no handlers are attached to an event?

Posted by Edward Tanguay on Stack Overflow See other posts from Stack Overflow or by Edward Tanguay
Published on 2010-03-19T16:20:38Z Indexed on 2010/03/19 16:31 UTC
Read the original article Hit count: 268

Filed under:
|
|

I am adding an event handler like this:

theImage.MouseMove += new MouseEventHandler(theImage_MouseMove);

but in my application, this code gets run every time the page is shown, so I want to attach the event handler only once, but how can I tell if a handler has been set yet or not, something like this:

if(theImage.MouseMove == null) //error
    theImage.MouseMove += new MouseEventHandler(theImage_MouseMove);

© Stack Overflow or respective owner

Related posts about c#

Related posts about events