How can i know whether the task in a tread is finished?

N

Norton

I would like to wait for the task finish in that thread before exit the sub
, how can i achieve this?

thx in advance!


Public Overridable Sub Convert()
Try
oThread = New Thread(AddressOf ConvertThread)
oThread.Name = "SIS Data Coversion"
oThread.Start()

Catch ex As Exception
Throw New
Exception(System.Reflection.MethodBase.GetCurrentMethod.Name, ex)
End Try
End Sub
 
L

Lubos Hrasko

That would defeat the point of multithreading...
take a look at Invoking a method when your thread finishes.

Example: (untested)

Public Overridable Sub Convert()
Try
Thread = New Thread(AddressOf ConvertThread)
Thread.Name = "SIS Data Coversion"
Thread.Start()
Catch ex As Exception
Throw New
Exception(System.Reflection.MethodBase.GetCurrentMethod.Name, ex)
End Try
End Sub


Public Delegate Sub AfterThread()
Private Sub OnAfterThread()
'thread is done
End Sub


Sub ConvertThread
'do long process
Invoke(New AfterThread(AddressOf OnAfterThread))
End Sub


Hope it helps,

Cheers,
Lubos
 
N

Norton

Thx for your help!

can u tell me where can i find the Invoke method?
(a stupid question but donno which i should import to make it work :p)

Thx
Norton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top