Re: Difference Between "Me.Close" and "End" for Exit Function
Originally Posted by Jericho
Just curious on what the difference is between the "Me.Close" and the "End" code for Visual Basic in terms of writing a Exit Button?
"End" and "Application.Exit" do a hard thread terminate. No events are raised and no cleanup code runs it simply terminates the thread (the application) at that point.
You should just use Me.Close on the main form to exit your app.
Currently using VS 2015 Enterprise on Win10 Enterprise x64.
Re: Difference Between "Me.Close" and "End" for Exit Function
Originally Posted by JuggaloBrotha
"End" and "Application.Exit" do a hard thread terminate. No events are raised and no cleanup code runs it simply terminates the thread (the application) at that point.
You should just use Me.Close on the main form to exit your app.
That's not quite true.
End does indeed terminate the application immediately. That's very bad, so you should NEVER use End.
Application.Exit exits the app no matter where it's called from, but all appropriate events are raised and all appropriate cleanup is performed. Application.Exit is generally what you should call when you want to exit the application, especially if you are not calling it from the main or last form. Note that calling Application.Exit does bypass the Closing and Closed events of your forms but FormClosing and FormClosed are raised.
Me.Close simply closes the current form. If the current form is the last or main form then that will also exit the app, depending on your shutdown settings.
Re: Difference Between "Me.Close" and "End" for Exit Function
Originally Posted by jmcilhinney
Application.Exit exits the app no matter where it's called from, but all appropriate events are raised and all appropriate cleanup is performed. Application.Exit is generally what you should call when you want to exit the application, especially if you are not calling it from the main or last form. Note that calling Application.Exit does bypass the Closing and Closed events of your forms but FormClosing and FormClosed are raised.
Really? Unless MSDN is wrong...
CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.
That's the documentation for .NET 1.1. It was an issue that Closing and Closed events were not raised when Application.Exit was called, which was the reason that they added the FormClosing and FormClosed events in .NET 2.0.
Re: Difference Between "Me.Close" and "End" for Exit Function
I guess I hadn't seen that .Net 1.1 doc came up first in the google search (why doesn't MSDN show which FW doc you're looking at on the pages anymore?)
In either case, I've never seen a need to do a hard exit ("End" or "Application.Exit") anyways.
Currently using VS 2015 Enterprise on Win10 Enterprise x64.
Re: Difference Between "Me.Close" and "End" for Exit Function
Originally Posted by techgnome
Oh but it does... it's in the TOC...
-tg
Right, but I was referring to the dropdown or whatever that was on the page, so you could change the FW doc version of the current page you're on. It used to sit conveniently in the top right and they took it out.
Currently using VS 2015 Enterprise on Win10 Enterprise x64.
Re: Difference Between "Me.Close" and "End" for Exit Function
OH... yeah... I know... I'm not sure what the thought was behind that thought process... I think in thier efforts to "simplify" it... they made it more confusing.
Re: Difference Between "Me.Close" and "End" for Exit Function
Originally Posted by JuggaloBrotha
Right, but I was referring to the dropdown or whatever that was on the page, so you could change the FW doc version of the current page you're on. It used to sit conveniently in the top right and they took it out.
They didn't take it out. They just gave you options. Click Preferences and select Classic view.