I was reading the MSDN documentation for the System.Windows.Forms.Form.OnClosing() method and noticed:
CAUTION: The OnClosing method is obsolete in the .NET Framework version 2.0; use the OnFormClosing method instead.
I can find no reference as to why it had been marked as obsolete.
I figured I would ask here:
The only difference I see is that you get access to the FormClosingEventArgs, so if you don't need those (which you obviously didn't if you were using OnClosing) then is there any benefit to switching to OnFormClosing?
I understand that obsolete means that it could go away, so you should update as soon as possible, but you and I both know that obsolete in MS land means little. I want to know solid technical details as to why.
I believe the main reason was to work around some of the inconsistencies with OnClosing, in particular, the fact that it is not called if the form is closing due to Application.Exit.
From the documentation:
The OnClosed and OnClosing methods are not called when the Application..::.Exit method is called to exit your application. If you have validation code in either of these methods that must be executed, you should call the Form..::.Close method for each open form individually before calling the Exit method.
The OnFormClosing provides access to the CloseReason member, which makes the handling much easier to handle correctly, in a clean, consistent manner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With