Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely stop running the code and exit the application?

In my code, I check if the executable file op.exe is in the application run path directory, in case if not, it does show MsgBox and exits the application, the problem is that it doesn't really exit the application, because the code after is executing everytime.

Here is the code I'm talking about:

    If Not File.Exists("op.exe") Then
        MsgBox("op.exe not found!", MsgBoxStyle.Critical, "Error")
        Application.Exit()
    End If
    IO.Directory.CreateDirectory('files')

MsgBox appears, and application does exit, but it's creating the directory files afterwards (IO.Directory.CreateDirectory('files')) . I dont want that, and I would like to completely close the application after showing the MsgBox.

How can I do that?

like image 235
Scott Avatar asked Nov 27 '12 22:11

Scott


1 Answers

Try Environment.Exit(0) instead. Application.Exit causes a message loop to exit, but that happens by the message loop reading a "quit" message from its queue. Environment.Exit causes the process itself to exit.

like image 98
prprcupofcoffee Avatar answered Oct 18 '22 18:10

prprcupofcoffee