[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

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
0
dba123
Asked:
dba123
3 Solutions
 
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.
0
 
sbarrow1Commented:
VB should take care of the collection as Idle Mind mentioned you can force garbage collection early by using gc.collect.
0
 
DeadlyTrevCommented:
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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now