Property Terminate VB.NET Console app

Posted on 2006-03-27
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
Question by:dba123
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    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.
    LVL 1

    Assisted Solution

    VB should take care of the collection as Idle Mind mentioned you can force garbage collection early by using gc.collect.
    LVL 6

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now