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

  • Home
  • SEARCH
  • 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 52955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:59:16+00:00 2026-05-10T16:59:16+00:00

Is there a way to tell if an event handler has been added to

  • 0

Is there a way to tell if an event handler has been added to an object? I’m serializing a list of objects into/out of session state so we can use SQL based session state… When an object in the list has a property changed it needs to be flagged, which the event handler took care of properly before. However now when the objects are deserialized it isn’t getting the event handler.

In an fit of mild annoyance, I just added the event handler to the Get property that accesses the object. It’s getting called now which is great, except that it’s getting called like 5 times so I think the handler just keeps getting added every time the object is accessed.

It’s really safe enough to just ignore, but I’d rather make it that much cleaner by checking to see if the handler has already been added so I only do so once.

Is that possible?

EDIT: I don’t necessarily have full control of what event handlers are added, so just checking for null isn’t good enough.

  • 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. 2026-05-10T16:59:17+00:00Added an answer on May 10, 2026 at 4:59 pm

    From outside the defining class, as @Telos mentions, you can only use EventHandler on the left-hand side of a += or a -=. So, if you have the ability to modify the defining class, you could provide a method to perform the check by checking if the event handler is null – if so, then no event handler has been added. If not, then maybe and you can loop through the values in Delegate.GetInvocationList. If one is equal to the delegate that you want to add as event handler, then you know it’s there.

    public bool IsEventHandlerRegistered(Delegate prospectiveHandler) {        if ( this.EventHandler != null )     {         foreach ( Delegate existingHandler in this.EventHandler.GetInvocationList() )         {             if ( existingHandler == prospectiveHandler )             {                 return true;             }         }     }     return false; } 

    And this could easily be modified to become ‘add the handler if it’s not there’. If you don’t have access to the innards of the class that’s exposing the event, you may need to explore -= and +=, as suggested by @Lou Franco.

    However, you may be better off reexamining the way you’re commissioning and decommissioning these objects, to see if you can’t find a way to track this information yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 51k
  • Answers 51k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer dbghelp library (straightforward): http://msdn.microsoft.com/en-us/library/ms679309(VS.85).aspx DIA SDK (more comprehensive, but COM):… May 11, 2026 at 6:33 am
  • added an answer True Persistence Ignorance. Complete POCO Support. No Magic String. May 11, 2026 at 6:33 am
  • added an answer SELECT TOP 500 CONVERT(INT, CONVERT(VARBINARY(16), NEWID())) FROM dbo.MyTable May 11, 2026 at 6:33 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.