Check for Finished Threads

Posted on 2009-12-17
Last Modified: 2012-05-08
I run several Threads to check values in a database.  When a thread is finished it writes back to its own label on the form.  When all threads are finished, I would like to add the total of all those labels.

Not sure how to do that - how to tell when each is done.

I've attached the code for one function (one thread)... the only difference between this one and the others is the goc.GetConnection variable and the goc.theTextBox.

Thanks for your help!




        TotalOrders.Text = CInt(hOrderCount.Text) + CInt(mOrderCount.Text) + CInt(gOrderCount.Text) + CInt(pOrderCount.Text)

Public Sub getHendersons()

        lblHendersons.ForeColor = Color.White

        Dim goc As New GetOrderArgs

        goc.getConnection = HendersonConnectionString

        goc.theTextBox = Me.hOrderCount

        goc.startDelegate = AddressOf GetOrderCount

        Dim t As New Thread(AddressOf goc.StartConnection)

        threadCount += 1

        t.Name = "Thread " & threadCount.ToString()

        t.IsBackground = True


    End Sub

Open in new window

Question by:slightlyoff
    LVL 17

    Expert Comment

    Create a global variable array, when each array finished, they can add a variable, like ID to that array. When you are creating a thread associate for example an ID to each and in thread code, when finished working, add ID of current thread to that global array.
    LVL 17

    Expert Comment

    Also you can create eventing system, like this:
    LVL 85

    Accepted Solution

    One approach is to use a "controller" thread that starts all the other threads and then waits for all of them to signal a ManualResetEvent with WaitAll().

    I have a simplified example here:
    LVL 1

    Author Closing Comment

    Thanks!  I had to re-work my program a little bit, but it works!


    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

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now