Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a specific event handler method already attached

Related to this question, Check if an event already exists

but the difference is I just want to know if a particular method is attached to the event. So there may be other methods attached, but I just want to know if a particular one exists.

My environment is C# in dotnet 4.0.

E.g.

Event += MyMethod1;
Event += MyMethod2;

// Some code
if (MyMethod1IsAttachedToEvent())
{
    // Achieved goal
}

Is this possible?

like image 884
Shiv Avatar asked Mar 06 '13 03:03

Shiv


People also ask

How do you check if an element has an event listener?

Right-click on the search icon button and choose “inspect” to open the Chrome developer tools. Once the dev tools are open, switch to the “Event Listeners” tab and you will see all the event listeners bound to the element. You can expand any event listener by clicking the right-pointing arrowhead.

How many ways can you attach an event handler to a DOM element?

There are two ways of event propagation in the HTML DOM, bubbling and capturing.

How do you link two events to a single event handler in Windows Forms?

To connect multiple events to a single event handler in C#Click the name of the event that you want to handle. In the value section next to the event name, click the drop-down button to display a list of existing event handlers that match the method signature of the event you want to handle.

Is an EventHandler a delegate?

The EventHandler delegate is a predefined delegate that specifically represents an event handler method for an event that does not generate data. If your event does generate data, you must use the generic EventHandler<TEventArgs> delegate class.


1 Answers

No. You cannot.

The event keyword was explicitly invented to prevent you from doing what you want to do. It makes the delegate object for the event inaccessible so nobody can mess with the events handlers.

Source : How to dermine if an event is already subscribed

like image 96
Parimal Raj Avatar answered Sep 20 '22 11:09

Parimal Raj