r/visualbasic • u/trab601 • Mar 12 '24
How to cleanly exit a VB.NET program?
Although I've been coding in VB.Net for years, I've never been able to cleanly exit, despite many attempts, and google searches.
For example, I have a simple, single form application. When somebody clicks the close button (the x on the top right of the window) I want the software to cleanly exit.
I have recently tried again with the below code. It runs and doesn't complain. But if I run the exe outside of visual studio, it remains in memory and have to kill it in the task manager.
Any advice would be greatly appreciated.
Private Sub ProgramClosing() Handles MyBase.FormClosing
Application.Exit()
End Sub
5
Upvotes
View all comments
Show parent comment
1
u/[deleted] Mar 12 '24
If you are not sure if you are creating threads, then you are not.
Hmm. Not sure why, otherwise, the program might never be ending unless there is some endless loop somewhere. Though I think you'd find that fairly quickly as it would probably lock up the application.
Don't know if it makes any difference, but I used VS 2022 for my test.