In the Main Method (Application Entry Point) of an application, checks occur to authenticate the user and to look for his/her authorization roles. All this happens before the
Application.Run is executed. If a user doesn't belong to a particular role then the application should immediately terminate. What method should you use for this?
Well,
Application.Exit won't be sufficient here because
Application.Run will still be executed after this statement and the application will start up. It's not like in VB6 that
End or
Ends (can't remember exactly) immediately terminates the entire application ...
The method Application.Exit 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.
This is how I did the security-checking at startup without making use of Application.Exit ...
When Application.Exit is called after Application.Run is executed then the method Run returns and you will be back at the Application Entry Point. Note that no validation code will run on your "open" forms!