Closing the entire application from a form

torisch

Newcomer
Joined
Jan 23, 2003
Messages
11
Location
Tromsø - Norway
Hi!

There is probably a simple solution to this question, but i have not been able to make it out.

I have an application that runs in mainform.vb. To log in to it, the user have to authenticate with username and passwd, which I ask for in a separate form called from form load. This form will be called again and again until the user types a correct user/passwd combination. My trouble is how I can close the entire application from the cancel button on the loginform. Now the user have to kill the application in Windows if he does not have the right user/passwd combination.

--
Tor Inge Schulstad
 
You will need to close the main form (the startup form) and it should
close the application by itself.
 
I have tried to do it this way:


Code:
'This goes in form load mainform.vb
Do While Not Authenticate(PubVar.BrukerNavn.ToString, PubVar.BrukerPassord.ToString)
       Dim b As New frmLogin(Db)
       b.Owner = Me
       b.ShowDialog()
Loop

'This goes in frmLogin Cancel button click handler
Private Sub btnLoginCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoginCancel.Click
       Me.Owner.Close()
End Sub

But then I only get a System.ObjectDisposedException
Any clues?
__
Tor Inge
 
A much simple solution will be to use the END instruction... put it where you want to end the app... and voila your app exits
 
I would rather use Application.Exit() due to the following:
(Quoted from help...)
The End statement can be placed anywhere in a procedure to end code execution, close files opened with an Open statement, and clear variables. The End statement calls the Exit method of the Environment class in the System namespace. System.Environment.Exit requires that you have SecurityPermissionFlag.UnmanagedCode permissions. If you do not, a SecurityException error occurs.

When executed, the End statement clears all variables at module and class level and all static local variables in all modules.

Note: 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.

With an additional keyword, End delineates the end of the definition of the appropriate procedure or block.

Cheers
 
Back
Top