Exit an application

shankar_it

Freshman
Joined
Jul 6, 2005
Messages
46
Do any one know a command to completly stop the program running .

I have a for loop which has a try and catch function

For Each MyFile In FilesArray
Try
MyFile.Delete()

Catch ex As Exception
MessageBox.Show("close all other wondows a run the program again", "DocumentManager Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

Application.Exit()
End Try

Next MyFile

i use application.exit() to end the program ,but the program runs till "for loop" ends.

ie if the looop goes into catch 2 times then it displays the message box twice.

Is there any other command to stop the program from completly running the first time enters the catch.I use vb.net for programming.
 
Just Use "Exit For" After The Messagebox Inside Your Catch Block

Visual Basic:
For Each MyFile In FilesArray
Try

MyFile.Delete()

Catch ex As Exception
MessageBox.Show("close all other wondows a run the program again", "DocumentManager Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

Exit For

Application.Exit()
End Try

Next MyFile


-=Simcoder=-
 
actually:

Visual Basic:
Try
[indent]For Each MyFile In FilesArray
[indent]MyFile.Delete()
[/indent]next MyFile
[/indent]Catch ex As Exception
[indent]MessageBox.Show("close all other wondows a run the program again", "DocumentManager Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
 
Application.Exit()
[/indent]End Try
 
joe yourcode was very helpfull since i was using this for loop inside a funtion and i do call this function 3 times in the same program.I have used try catch whenever i call this function instead of using it in for loop.since i am new to java and VB.net i really don't know much about try catch.
 
Back
Top