Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi how to know when a work in a thread is complete?
VB
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim firstThread As New Thread(AddressOf Fu1)
        firstThread.Start()

'I want to determine the job of sub (Fun) is finished and then run other code. Normally if i add other code after firstThread.Start() code is running before completed job of Fun (Codes after firstThread.Start() is depended on finished Fun)
End Sub

Sub Fun()
'Something code is here

End Sub
Posted
Updated 6-Jun-12 22:12pm
v2

For a thread you have the myThread.IsAlive property. It is false if the thread method returned or the thread was aborted.

Look at MSDN [^]for details.
 
Share this answer
 
Comments
ali.hnd 7-Jun-12 4:22am    
How to check myThread.IsAlive property? I can't do that by while loop because program is busy during loop is running.
VB
Dim firstThread As New Thread(AddressOf Job1)
Dim SecondThread As New Thread(AddressOf Job2)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        
        firstThread.Start()
        SecondThread.Start()

End Sub

Sub Job1()

'Something code is here

End Sub

Sub Job2()
        While (Job1.IsAlive)
        End While
'Job 2
End Sub
 
Share this answer
 
Hi try to look forward on Join method.

VB
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim firstThread As New Thread(AddressOf Fu1)
        firstThread.Start()
        firstThread.Join()

'I want to determine the job of sub (Fun) is finished and then run other code. Normally if i add other code after firstThread.Start() code is running before ompleted job of Fun (Codes after firstThread.Start() is depended on finished Fun)
End Sub

Sub Fun()
'Something code is here

End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900