Which method is better and why, when?
In terms of scalability,performance etc which one is better?
From my point of view coding by hand is better and more natural. what do you guys think?
Which method is better and why, when?
In terms of scalability,performance etc which one is better?
From my point of view coding by hand is better and more natural. what do you guys think?
I hate to tell you, but they ar epretty much identical. What exactly are you referring to?
If I put an event into a control in the IDE, the code is generated.
Do you mean manually adding += event handler methods vs. having them added in the auto-generated files? (like .Designer.cs for WinForms).
I don't think it matters. The important thing is to remember to detach -= the event handlers when appropriate to stop references keeping objects from being garbage collected. IMO it is easier to keep track of of it all if you do it all by hand.
I thing that performance (when talking about events) should be calculated based not on how fast a reference is created but instead on how much will your application leak in the end.
These are four cases graded from 1 to 5 at how highly I would consider using WeakReference:
[1] - WeakReference is nearly useless in Asp.Net as log as you don't have static events. I might be terribly wrong here so please correct me if I'm missing something.
[2] - In small Windows application you are working on all by yourself you could remove reference by hand.
[4] - In big windows application you are working on in a team I would use weak references because one of your colleagues might miss or forget removing a handler. This can be seemed as a minor bug for him but it might leak dozen of objects in the end. This is especially true for developers who haven't been programming for long enough and just don't know that event handler should be removed by hand.
[5] - If you are creating a big pluggable application with external API then weak references are must have.