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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:01:14+00:00 2026-05-11T18:01:14+00:00

Consider this scenario. I have an object, lets call it…. Foo. Foo raises a

  • 0

Consider this scenario. I have an object, lets call it…. Foo. Foo raises a simple event named “Loaded”. As part of the information for the event, consumers will need to know which foo object raised the event. Our team has adopted the following pattern.

1) Create a new class that inherits from EventArgs – for example,
FooEventArgs : System.EventArgs.

2) Add a property of type Foo to the FooEventArgs, which is set by being passed in via the constructor.

3) Declare the event using the generic version of EventHandler, so

public event EventHandler<FooEventArgs> Loaded;

4) Raise the event from the Foo class with the following signature:

Loaded(this, new FooEventArgs(this));

Essentially what this does is makes the “sender” the foo object, but it also puts the foo object reference into the event argument as a strongly typed property.

One advantage for doing this is that no one has to bother with casting “sender” when they handle the event, which lowers the coupling between the event consumer and the event raiser. Another “advantage” is that if the type of the event raiser ever has to change, and hence the strongly typed property (which hopefully never happens), then instead of simply having code start to fail on the cast when it comes out as null, the API actually breaks so it can be fixed at compile time.

To me, this pattern seems like it might be overkill. Should they be trusting the “sender” parameter more, and ditching the custom event arguments? My team argues that no one really uses the sender parameter. What’s the best practice for passing out a reference to the event-raising object?

EDIT: Great feedback so far, I’ll leave this open for another day or so before I accept one.

  • 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-11T18:01:14+00:00Added an answer on May 11, 2026 at 6:01 pm

    The common pattern is to use sender and not add the sender separately to the EventArgs. The custom EventArgs is used for other state like a tree node for a tree event, a (settable) boolean for a cancelable event etc.

    We use the common pattern since it is used by the BCL classes also, and making a difference for “self-made events” is potentially confusing. Also, we have a global IoC publisher-subscriber pattern but this one only works with the normal EventHandler delegate signature, since the types are not known in advance. In this case, a cast (for instance to a custom EventArgs) is necessary anyways, so we might just as well cast the sender.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • 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
  • Editorial Team
    Editorial Team added an answer Take a look at the CodeIgniter manual on Sessions and… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer You can obfuscate it, but there's no way of protecting… May 11, 2026 at 11:48 pm
  • Editorial Team
    Editorial Team added an answer Use XOR: SELECT value ^ 256 So in your case,… May 11, 2026 at 11:48 pm

Related Questions

Consider this scenario. I have an object, lets call it.... Foo. Foo raises a
Let's say I have a table that represents a super class, students . And
(Note: these two questions are similar, but more specific to ASP.Net) Consider a typical
This is a question for a WSS/SharePoint guru. Consider this scenario: I have an
Consider this scenario: I've an XML file called person.xml with the following data in

Trending Tags

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

Top Members

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.