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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:06:43+00:00 2026-05-16T01:06:43+00:00

I have a collection-based project in .NET 4. What I mean is that, I

  • 0

I have a collection-based project in .NET 4. What I mean is that, I have a master collection, call it “System”, which is made up of frames, which are each made up of cards, which are in turn made up of channels. So, it looks like System->Frame->Card->Channel. All these are represented as objects, and there is a Parent-Child relationship between them. Essentially, Channel is only exposed to Card, Card is only exposed to Frame, and Frame is only exposed to System.

Ideally, I would wish to expose methods only from the System class to the outside world. However, there are crucial events that occur in Channel, Card, and Frame classes. Currently, the way I handle them is through propagation. Suppose an event occurred in Channel. This event is first raised in Card, then in Frame, and then finally in System. You can see how this results in a lot of code. But my main concern is not of code, but of performance.

Do you think this propagation effects my performance badly? Is there a way to make it more efficient? What other options do I have? My collections are relatively small. System is 1, Frames < 16, Cards < 256, Channels < 8192. Most of the data is stored in the Channel class, which only has primitive objects within it.

EDITS

Here is the code I have in Card for an event that is raised by a Channel:

protected virtual void OnChannelPropertyChanged(Object sender, PFPropertyChangedEventArgs e)
    {
        try
        {
            EventHandler<PFPropertyChangedEventArgs> handler = ChannelPropertyChanged;
            TestEventArgs_ChannelPropertyChanged = e;
            if (handler != null)
            {
                handler(sender, e);
            }
        }
        catch (Exception ex)
        {
            Milltown.MTCore.mtException mtEx = new Milltown.MTCore.mtException((int)PFExceptions.Exception_Hidden_FuctionLevel, ex,
            PFCommonVariables.ApplicationPlatform, PFCommonVariables.ApplicationDataSource, "PFCard:OnChannelPropertyChanged");
        }
    }

And when I add a Channel to a Card within the Card class, I call:

channel.ChannelPropertyChanged += this.OnChannelPropertyChanged;
  • 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-16T01:06:44+00:00Added an answer on May 16, 2026 at 1:06 am

    The only way to answer whether or not affects your performance would be to test it: try it one way where you propogate the events, then another where you attach directly. See which is faster.

    That being said, I can’t imagine that you’re going to find much–if any–measurable impact on performance when you have a few sequential delegate invocations instead of just one. Yes, delegates are slightly slower to invoke than actual methods, so, all things being equal, adding more levels of indirection has a bigger impact than the same level with regular method calls, but this smells of premature optimization.

    Your approach is what I would recommend if someone asked how to do what you’re after. Go with it unless it’s a problem.

    EDIT

    In response to your comment on another answer, I wanted to expand. C# events have what’s called “property syntax”. If implemented explicitly in a class, it looks something like this:

    private EventHandler eventDelegate;
    
    public event EventHandler MyEvent
    {
        add { eventDelegate += value; }
        remove { eventDelegate -= value; }
    }
    

    (Actually, it uses Delegate.Combine, but that’s immaterial here)

    When you attach to an event, it actually calls the add code, passing in the delegate to attach as value; the same is true for remove.

    When you use the shorthand event syntax like this:

    public event EventHandler MyEvent;
    

    It actually generates code under the covers that’s very similar to what I posted above. However, if you make it explicit, you can do whatever you like in the add and remove handlers. This means that you can redirect the target delegate somewhere else. In the case of the other answer, it’s redirecting the delegate to a child object.

    This will work if and only if the following are true:

    1. There is a 1:1 correlation between parent and child, and the related object won’t change
    2. Exposing a reference to the child object (as object) is acceptable

    If you have multiple children, it’s technically possible to do (you could just loop through and attach to all of them in the add and remove all of them in remove), but is much more difficult to manage. If the related object or the collection of objects can change after the event is attached, then it becomes virtually impossible to coordinate.

    Additionally, if your events follow the recommended practices for events (where you pass the triggering object as sender), then because you’re attaching the target directly to the child event rather than raising it yourself, then you’ll be exposing a reference to the child object through this argument. I have no idea if that’s relevant or acceptable to you, but it’s something that should be considered.

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

Sidebar

Related Questions

I have a collection of objects to which I'd like to just add a
I have a collection of classes that inherit from an abstract class I created.
I have a collection of non-overlapping rectangles that cover an enclosing rectangle. What is
We have a collection of commercial MFC/C++ applications which we sell using Stingray Objective
I have a collection of classes that I want to serialize out to an
I have a collection of elements that I need to operate over, calling member
I have a collection of unmanaged dlls with a C# wrapper around them that
I have a collection of custom entity objects one property of which is an
I have a base class (written using C#.net) which uses datasets to pull data
I have a project which stores values in SQL and later retrieves them for

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.