Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 274675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:38:47+00:00 2026-05-12T00:38:47+00:00

I want to be able to find out if an event is hooked up

  • 0

I want to be able to find out if an event is hooked up or not. I’ve looked around, but I’ve only found solutions that involved modifying the internals of the object that contains the event. I don’t want to do this.

Here is some test code that I thought would work:

// Create a new event handler that takes in the function I want to execute when the event fires
EventHandler myEventHandler = new EventHandler(myObject_SomeEvent);
// Get "p1" number events that got hooked up to myEventHandler
int p1 = myEventHandler.GetInvocationList().Length;
// Now actually hook an event up
myObject.SomeEvent += m_myEventHandler;
// Re check "p2" number of events hooked up to myEventHandler
int p2 = myEventHandler.GetInvocationList().Length;

Unfort the above is dead wrong. I thought that somehow the “invocationList” in myEventHandler would automatically get updated when I hooked an event to it. But no, this is not the case. The length of this always comes back as one.

Is there anyway to determine this from outside the object that contains the event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:38:47+00:00Added an answer on May 12, 2026 at 12:38 am

    There is a subtle illusion presented by the C# event keyword and that is that an event has an invocation list.

    If you declare the event using the C# event keyword, the compiler will generate a private delegate in your class, and manage it for you. Whenever you subscribe to the event, the compiler-generated add method is invoked, which appends the event handler to the delegate’s invocation list. There is no explicit invocation list for the event.

    Thus, the only way to get at the delegate’s invocation list is to preferably:

    • Use reflection to access the compiler-generated delegate OR
    • Create a non-private delegate (perhaps internal) and implement the event’s add/remove methods manually (this prevents the compiler from generating the event’s default implementation)

    Here is an example demonstrating the latter technique.

    class MyType
    {
        internal EventHandler<int> _delegate;
        public event EventHandler<int> MyEvent;
        {
            add { _delegate += value; }
            remove { _delegate -= value; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to find out which DOM elements are present in
I want to be able to replicate only the folder structure (not the contents)
I want to be able to use a wildcard in string::find and then fetch
I want to be able to limit Perl's File::Find to a directory depth (below
I want to be able to take an image that i have already captured
I have looked everywhere for a simple answer to this but I have not
I want to create a handler that can be used to handle any event
So I've been searching around and cannot find out exactly how to do this.
This question doesn't relate only to MouseEvent.CLICK event type but to all event types
I want to be able to do Artist.case_insensitive_find_or_create_by_name(artist_name) [1] (and have it work on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.