Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Threading VB.NET
Hi
how to know when a work in a thread is complete?
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 6-Jun-12 23:06pm
ali.hnd223
Edited 6-Jun-12 23:12pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
ali.hnd at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi try to look forward on Join method.
 
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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 9 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100