Threading question

G

Geert M

I use a ticker and every 5 minutes he fires of a new thread and does stuff.

Private Sub tmprocess_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmprocess.Tick
ProcessThread = New Threading.Thread(AddressOf Domysms)

ProcessThread.Start()

End Sub

The problem is that I only want to start a new thread if the previous thread
has ended. How can I do this?

Regards

Geert
 
C

Cor

I think, that you can throw an event at the end of the thread
handles that to set a swready in your mainthread
and then
if swReady processThread.Start()
swReady = false
 
P

Prateek

Hi,

You may use the Thread.IsAlive property here to determine if the previous
thread is still active. The following code should meet your requirement.
(The Is Nothing check is relevant only for the first time)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

If ProcessThread Is Nothing Then

ProcessThread = New Threading.Thread(AddressOf Domysms)
ProcessThread.Start()

End If

If ProcessThread.IsAlive Then Exit Sub

ProcessThread = New Threading.Thread(AddressOf Domysms)

ProcessThread.Start()

End Sub

Cheers
-Prateek


I use a ticker and every 5 minutes he fires of a new thread and does stuff.

Private Sub tmprocess_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmprocess.Tick
ProcessThread = New Threading.Thread(AddressOf Domysms)

ProcessThread.Start()

End Sub

The problem is that I only want to start a new thread if the previous thread
has ended. How can I do this?

Regards

Geert
 

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

Similar Threads


Top