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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:09:21+00:00 2026-06-13T11:09:21+00:00

Possible Duplicate: Why should events in C# take (sender, EventArgs)? I just ran the

  • 0

Possible Duplicate:
Why should events in C# take (sender, EventArgs)?

I just ran the VS2012 Code Analysis tool on a project and found that it complains about this snippet:

public delegate void PerMbHandler(long totalMb);

public event PerMbHandler NotifyMegabyteIncrement;

CA1009 Declare the second parameter of ‘MyWebClient.PerMbHandler’ as an EventArgs, or an instance of a type that extends EventArgs, named ‘e’.

MSDN explains:

Event handler methods take two parameters. The first is of type System.Object and is named ‘sender’. This is the object that raised the event. The second parameter is of type System.EventArgs and is named ‘e’. This is the data that is associated with the event. For example, if the event is raised whenever a file is opened, the event data typically contains the name of the file.

MSDN states simply what the convention is, not the reason it exists.

What can go wrong using a long parameter rather than a subclass of EventArgs? Is it a matter of convention and programmer expectations, or is there some subtle technical reason that the pattern must be followed? I say subtle, because the code seems to work fine.

  • 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-13T11:09:22+00:00Added an answer on June 13, 2026 at 11:09 am

    What can go wrong using a long parameter rather than a subclass of
    EventArgs?

    Event Args
    It’s not wrong per se but it’s not extensible. For sake of argument, perhaps in 6 months you need to pass two longs, or add a string, or add a whole list of information. With EventArgs in the signature, you can pass any derived type and not break existing consumers; with a specific value type, you are very limited.

    EventArgs also allows you to communicate with the class that raised the event, e.g. CancelEventArgs.

    Sender
    Honestly, I rarely use sender for anything. It can also be somewhat ambiguous. For example, a custom event on a control triggered by input into a textbox…who is the sender? the textbox (probably more useful), or the control which declares the custom event?

    Still, it is a familiar convention, and with a well-documented interface it can be useful.

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

Sidebar

Related Questions

Possible Duplicate: Why should I use templating system in PHP? I was just curious
Possible Duplicate: What should a good BugTracking tool be capable of? Although there is
Possible Duplicate: Should I use != or <> for not equal in TSQL? Behavior
Possible Duplicate: Should Usings be inside or outside the namespace sa1200 All using directives
Possible Duplicate: Should C++ eliminate header files? In languages like C# and Java there
Possible Duplicate: Should PHP 'Notices' be reported and fixed? Till date i was ignoring
Possible Duplicate: Should ‘else’ be kept or dropped in cases where it’s not needed?
Possible Duplicate: Tasks should show up only if the user has been assigned it
Possible duplicate of: should-i-link-to-google-apis-cloud-for-js-libraries also many other discussions, including: Where do you include the
Possible Duplicate: Why should the interface for a Java class be prefered? When should

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.