We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Property Terminate VB.NET Console app

dba123
dba123 asked
on
Medium Priority
471 Views
Last Modified: 2006-11-18
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
Comment
Watch Question

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Commented:
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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.