Is there anyway to clear all handlers for an event?  
Author Message
Nickeay





PostPosted: Visual C# General, Is there anyway to clear all handlers for an event? Top

hi,

I am just thinking if there is a way to remove all handlers for an event, like
button1.Click += new MyEventHander(OnButton1Click);
button1.Click += new EventHandler(OnButton1StandardClick);
...
I think you can hook up as many as you want handlers to a single Click event. The question is how to remove all of them Is it the only way that remove one by one by using -=
Thanks.



Visual C#3  
 
 
Mattias Sjogren





PostPosted: Visual C# General, Is there anyway to clear all handlers for an event? Top

From outside the class, that's the only way. Inside the class providing the event you can simply set the delegate reference to null.



 
 
Udhaya Kumar D





PostPosted: Visual C# General, Is there anyway to clear all handlers for an event? Top


EventHandlerList eventsList = this.Events;
eventsList.Dispose();

Just removes all the events related to the Form or UserControl