How to completely stop code execution and exit the application?

In my code, I check if the op.exe executable file op.exe in the directory of the application startup path, if not, it shows MsgBox and exits the application, the problem is that it really does not exit the application, because the code is executed every time after .

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 the application exits, but then creates the files directory ( IO.Directory.CreateDirectory('files') ). I do not want this, and I would like to completely close the application after showing MsgBox.

How can i do this?

+7
source share
1 answer

Try Environment.Exit(0) . Application.Exit causes the message loop to exit, but this happens in the message loop by reading the "quit" message from its queue. Environment.Exit forces the process to exit.

+18
source

All Articles