Difference Between "Me.Close" and "End" for Exit Function
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?
Re: Difference Between "Me.Close" and "End" for Exit Function
What are you trying to do?
Re: Difference Between "Me.Close" and "End" for Exit Function
Quote:
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.
Re: Difference Between "Me.Close" and "End" for Exit Function
Quote:
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
Quote:
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...
Quote:
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.
Application.Exit Method, first MSDN link on a google search.
Re: Difference Between "Me.Close" and "End" for Exit Function
Quote:
Originally Posted by
JuggaloBrotha
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.
http://msdn.microsoft.com/en-us/library/ms157894.aspx
Quote:
The Exit method does not raise the Closed and Closing events, which are obsolete as of .NET Framework 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.
1 Attachment(s)
Re: Difference Between "Me.Close" and "End" for Exit Function
Oh but it does... it's in the TOC...
-tg
Re: Difference Between "Me.Close" and "End" for Exit Function
Quote:
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.
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.
-tg
Re: Difference Between "Me.Close" and "End" for Exit Function
Quote:
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.
Re: Difference Between "Me.Close" and "End" for Exit Function
Quote:
Originally Posted by
jmcilhinney
They didn't take it out. They just gave you options. Click Preferences and select Classic view.
What "Preferences" ? I don't see any such link for Preferences on MSDN.
-tg
Re: Difference Between "Me.Close" and "End" for Exit Function
Quote:
Originally Posted by
techgnome
What "Preferences" ? I don't see any such link for Preferences on MSDN.
-tg
It's in the top right corner.
Re: Difference Between "Me.Close" and "End" for Exit Function
ahh.... if one is logged in... which most of the time I'm not. Got it.
-tg