Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all eventhandler [duplicate]

Lets say we have a delegate

public delegate void MyEventHandler(string x);

and an event handler

public event MyEventHandler Something;

we add multiple events..

for(int x = 0; x <10; x++)  
{
   this.Something += HandleSomething;
}

My question is .. how would one remove all methods from the eventhandler presuming one doesn't know its been added 10 (or more or less) times?

like image 678
Eminem Avatar asked Mar 18 '16 12:03

Eminem


People also ask

How do I get rid of EventHandler?

Go to the objects tab, view the Document object (don't click on edit) and scroll down to Event Handlers. Select the one to delete and press delete.

How do I delete all event listeners at once?

To remove all event listeners from an element: Use the cloneNode() method to clone the element. Replace the original element with the clone. The cloneNode() method copies the node's attributes and their values, but doesn't copy the event listeners.

Which mode allows you to remove all event listeners from an element?

removeEventListener() The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget. addEventListener() from the target.


1 Answers

Simply set the event to null:

this.Something = null;

It will unregister all event handlers.

like image 186
Patrick Hofman Avatar answered Sep 28 '22 04:09

Patrick Hofman