Killing a VB.NET app

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I kill a VB app from the constructor of the main form? I am popping up a log in window, and if the login fails, I want the application to exit.
 
Sean said:
How do I kill a VB app from the constructor of the main form? I am popping
up a log in window, and if the login fails, I want the application to exit.

Have you tried Environment.Exit() ?

However, a much cleaner method in my opinion would be to first display the
login form and then create and display the main form only if the login was
successfull.

You will need to achieve that to have a Main() method instead of lauching
your app directly with the Main Form. In the main method, you can display
the login form (with loginForm.ShowDialog() for example), check the results
and either show the main form (with Application.Start(new MainForm()) for
example) or do nothing (which will cause the application to stop itself).
Clean and a much easier to understand logic.
 
* "=?Utf-8?B?U2Vhbg==?= said:
How do I kill a VB app from the constructor of the main form? I am
popping up a log in window, and if the login fails, I want the
application to exit.

Throw an exception and catch it in your 'Sub Main'.
 
Back
Top