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 8439919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:08:28+00:00 2026-06-10T08:08:28+00:00

I would like to confirm something – when I register a method as a

  • 0

I would like to confirm something – when I register a method as a subscriber to an event the long way, like so:

_serviceContext.ReadingEntity += new EventHandler<ReadingWritingEntityEventArgs>(_serviceContext_ReadingEntity);

I need to un-register that method from the event’s subscription if I don’t want it to continue to be called when the event is fired, like this:

_serviceContext.ReadingEntity -= new EventHandler<ReadingWritingEntityEventArgs>(_serviceContext_ReadingEntity);

When I register a delegate as a subscriber to an event, like so:

public guy ThisMethod()
{
    _serviceContext.ReadingEntity += delegate(object sender, ReadingWritingEntityEventArgs e)
        {

        };
}

There is no way to un-register that delegate from the subscriber list from that method. So I am assuming that the scope of this registration is limited to the method in which it’s registered – i.e. if the _serviceContext.ReadingEntity event was fired in a method called by ThisMethod, this registration would be already expired and the code inside the delegate would not run. Is this correct?

Thanks!

p.s. I realize that the first “long” way of registering an event handler also has scope limitations, but I’m a bit hazy on that. My main question, however, is whether or not the delegate registration will live on outside of the method above.

  • 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-06-10T08:08:29+00:00Added an answer on June 10, 2026 at 8:08 am

    Once you subscribed a delegate this way (you can unsubscribe using -= operator if you cache the delegate variable somewhere) you can’t remove it from subscribers list and it will be invoked every time event rises until publisher is alive. Moreover this subscription will prevent any subscriber class (class which contains the method you subscribed to event) from garbage collection until publisher is alive (unless you use a static method).

    To give some clarity, there is no “anonymous” methods in IL code. All your delegates and lamdbas are translated into static/instance methods and closure classes (depends on whether they use instance members/function parameters).

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

Sidebar

Related Questions

I am learning Android via a book and would just like to confirm something.
I would like to us Fancybox for confirm messages before a user deletes something.
I would like a way to have a confirm box pop up when a
I would like to confirm whether I am on the right track when identifying
I imagine two, but I would like to confirm if I am making sense
I have a confusion regarding DataContext which i would like someone to confirm or
I have a RadioButtonList control and I would like to do a Javascript confirm
and it's linked to a 'confirm comment deleted page. Ideally I would like it
What would a simple unit test look like to confirm that a certain controller
I have a gridview with the onRowDeleting method implemented. I would like to prompt

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.