07.19.07
Exit program in vb .net (application.exit)
What methods are there?
- System.Windows.Forms.Application.Exit() - Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed. This method stops all running message loops on all threads and closes all windows of the application. This method does not force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return. To exit a message loop for the current thread only, call ExitThread. This is the call to use if you are running a WinForms application. As a general guideline, use this call if you have called System.Windows.Forms.Application.Run.
- System.Environment.Exit(exitCode) - Terminates this process and gives the underlying operating system the specified exit code. This call requires that you have SecurityPermissionFlag.UnmanagedCode permissions. If you do not, a SecurityException error occurs. This is the call to use if you are running a console application.
- End - (Visual Basic only) Terminates execution immediately. The End statement can be placed anywhere in a procedure to end code execution, close files opened with an Open statement, and clears variables at module and class level and all static local variables in all modules. The End statement calls System.Environment.Exit. The End statement stops code execution abruptly, without invoking the Finalize method or any other Visual Basic code. Object references held by other programs are invalidated. The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created and no code executing.
I want to close the application and I want to close it now
For instance you are handling an exception yourself and want the program to terminate immediately. Then you should do it with Environment.Exit(0)
You would like to exit your windows form based application in a clean way.
You are calling the routine from a menu item. You should use application.exit