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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:47:34+00:00 2026-05-13T09:47:34+00:00

Note: I edited this question to make it easier for other people with the

  • 0

Note: I edited this question to make it easier for other people with the same problem to get help here. To see the original question that fits better with some of the answers, check the edit history.

In a project I have a ExecutionManager class that can contain multiple ExecutionSlot’s instances. The ExecutionSlot class have several public event fields like this:

public event EventHandlers.ObjectEventHandler<IPlugin> ExecuteCompleted;

For each of these events there is a matching event on ExecutionManager. The desired behavior is that every time on of the ExecutionSlot’s raises an event, the matching event is also raised on the containing ExecutionManager.

The implmented solution was that whenever an ExecutionSlot was added to an ExecutionManager the ExectionManager would add its own events to the ExecutionSlot’s like this:

executionSlot.ExecuteCompleted += ExecuteCompleted;

There is no need yet to remove an ExecutionSlot, so the events are never removed either.

The problem is that the event on ExecutionManager is not being raised. After confirming that an event was being reaised by an ExecutionSlot I found out that changing the above line to the following fixed the problem:

executionSlot.ExecuteCompleted += (sender, eventArgs) => ExecuteCompleted(sender, eventArgs);

And I could not figure out why, so my question was, what the difference was.

The reason for this difference was that the first adds the current listeners of the ExecutionManager’s event to the ExecutionSlot’s event. So any listeners added later will not be called when the event is raised.
In contrast the latter solution uses a lambda to raise the ExecutionManager’s event, which means that the listeners at the time of the event will be called.

The underlying reason for the first solution to fail, is that delegates are immutable. So when you add a new delegate to and event, you are actually creating a new delegate that contains the existing delegates and the added. So any reference to the delegates made before will not contain the newly added delegate.

  • 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-13T09:47:34+00:00Added an answer on May 13, 2026 at 9:47 am

    look at this other post on stackoverflow

    b += (s, e) => a(s, e);
    

    is not the same as

    b += a;
    

    It appends the current contents of a to b, so if later more handlers enlist with a, this will not cause them to be called when b is fired

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

Sidebar

Related Questions

Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Note : The code in this question is part of deSleeper if you want
Note This is not a REBOL-specific question. You can answer it in any language.
I realize this is kind of a long question, but I saw no other
Moderator note: This question is not a good fit for our question and answer
[EDITED: I left the original question below, with some more context and code to
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Note: This was posted when I was starting out C#. With 2014 knowledge, I
Note The question below was asked in 2008 about some code from 2003. As
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column

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.