Improve company productivity with a Business Account.Sign Up

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

delay starting a thread until a previous thread is completed

HOw can I delay the start of a thread until a previous thread has completed. My code is as follows:

 Dim Q As Thread
             Q = New Thread(AddressOf invtransfer)
             Q.Name = "putaways_one"
             Q.Start()

            dim R as Thread
            r = new Thread ( AddressOf of runsql)
            r.Name = "putaways_two"
             r.Start()

I want thread R to start after thread Q has exited.  Should I use a Do while loop until status of threadQ is complete?
0
fidman
Asked:
fidman
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is one way:

    Dim Q As Thread
    Q = New Thread(AddressOf invtransfer)
    Q.Name = "putaways_one"
    Q.Start()

    Q.Join() ' Block calling thread until Q has finished

    dim R as Thread
    r = new Thread ( AddressOf of runsql)
    r.Name = "putaways_two"
    r.Start()

Regards,

Idle_Mind
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Just a thought though...

If you make your code block with either the Join() method as I have, or a Do...While loop as you propose, why use a thread in the first place?

Idle_Mind
0
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.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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