Property Terminate VB.NET Console app

What is the proper way to stop and clean up after the items that are done runing in my Sub Main are done running?  Is there a garbage colletion, threads, and/or other items I need to free up in VB.NET or does it take care of itself?  It seems as though when Debug is done running, it's still locking some of the incoming txt files that I use to process and test with.  My app manipulates these txt files so I wonder if I need to stop it properly at the end with some functions
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
You can speed things up by calling the close method on your StreamReaders (or whatever you are using).

But in answer to your question...typical code should automatically get cleaned up and garbage collected when you sub main exits.
VB should take care of the collection as Idle Mind mentioned you can force garbage collection early by using gc.collect.
If you want to be thorough (and you should be);
    Everything you New, set it to Nothing when you're finished
    Everything you open (DB connections, files, streams, interfaces, devices, etc) you must close
    Any COM objects you create or cause to be created should be disposed and set to nothing
    Terminate threads and stop timers
    All forms should be closed
Application.Exit takes care of the last couple.

Part of your problem is likely the Visual Studio IDE, not your program.  My experience with debugging is that the IDE will frequently leave files opened, devices references, connections hanging and COM interop in god knows what state.  Kill the IDE and restart it whenever you are debugging and notice unusual behaviour.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.