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