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

  • Home
  • SEARCH
  • 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 612089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:51:19+00:00 2026-05-13T17:51:19+00:00

I understand how to use Events according to Net Framework guidelines, but what are

  • 0

I understand how to use Events according to Net Framework guidelines, but what are the benefits of using this pattern?

http://msdn.microsoft.com/en-us/library/aa645739%28VS.71%29.aspx :

The .NET Framework guidelines indicate that the delegate type used
for an event should take two parameters, an “object source” parameter
indicating the source of the event, and an “e” parameter that
encapsulates any additional information about the event. The type of
the “e” parameter should derive from the EventArgs class. For events
that do not use any additional information, the .NET Framework has
already defined an appropriate delegate type: EventHandler.

a) I see some benefits in using “object source” value as a first parameter since there are situations where multiple objects can have their events set to the same method. Thus, if for example we have 10 objects and if all 10 objects set their events to event handler M, then inside M we can use “object sender” parameter value to identify the initiator of the event call.

  • But as far as I can tell, ”object source” parameter is only useful if event was raised inside an instance method. Thus, if event was raised inside static method, then “object source” parameter is of no use?!

b) Are there other benefits of using events with accordance to Net Framework guidelines?

c) Whatever the benefits may be, why would they out-weight the trouble of having to

  • write an additional code to put the desired arguments into an object derived from EventArgs
  • write an additional code inside event handlers to extract information from object derived from EventArgs ?

thank you

  • 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-13T17:51:20+00:00Added an answer on May 13, 2026 at 5:51 pm

    As far as I see it there are two major benefits:

    • People writing code consuming the event will recognize the pattern and immediately know how to use the event
    • The signature of the event is crafted in a way that it is robust towards change

    The first point should be pretty obvious, not needing a lot of elaboration.

    As for the second point, there are two reasons for this (in my opinion). First, since sender is object, the event signature can be reused by several types. Second, since the second parameter is an EventArgs decendant, when you introduce your own EventArgs class this class can be extended later without altering the signature of the event.

    Update
    Response to questions:

    I’m not sure what you mean by “ being
    able to extend EventArgs without
    altering the signature of the event”?!

    Let’s take an example, take the following class:

    public class SomeClass
    {
        public event EventHandler<FileEventArgs> SomethingHappened;
    }
    public class FileEventArgs : EventArgs
    {
        public FileEventArgs(string filename)
        {
            Filename = filename;
        }
        public string Filename { get; private set; }
    }
    

    Then we have a consumer that listens to the SomethingHappened event:

    static void SomethingHappenedHandler(object sender, FileEventArgs e)
    {
        // do something intelligent
    }
    

    Now, lets say that we want to extend the information that we transfer in the event with information about what happened to the file:

    public enum WhatHappened
    {
        Copy,
        Rename,
        Delete
    }
    public class FileEventArgs : EventArgs
    {
        public FileEventArgs(string filename, WhatHappened whatHappened)
        {
            Filename = filename;
            WhatHappened = whatHappened;
        }
        public string Filename { get; private set; }
        public WhatHappened WhatHappened { get; private set; }
    }
    

    Now, if we had chosen to send the filename as a parameter in the event itself, we would need to alter the event signature by adding another parameter, effectively breaking all code that listens to the event. But since we in the code above have simply just added another property to the FileEventArgsclass, the signature remains unchanged, and no listeners need to be updated (unless they want to use the newly added property, that is).

    Am I write in assuming that if event
    is raised inside static method, then
    “object source” parameter is of no
    use?!

    Yes, that is correct. I typically pass null as the sender argument from static events (which, honestly, is very rare).

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

Sidebar

Related Questions

I understand the benefits of events using delegate types with signature delegate void delegate_name(object
I can easily understand how to use custom events in pure C# code, but
I'm learning MVC and trying to follow some tutorials and this video http://channel9.msdn.com/Events/DevDays/DevDays-2011-Netherlands/Devdays002 In
I can understand the use for one level of namespaces. But 3 levels of
I understand how to use REST for doing general entity interactions - using urls
How do I select the calendar to use when creating events using the Zend
I use C# Entity Framework and Asp.net Web Forms 4. At the moment I'm
I have developed a C# application which makes heavy use of events. Now this
I'm trying to understand when it is appropriate to use events. It seems to
I want to understand the use of xargs man in Rampion's code : screen

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.