Threading question

  • Thread starter Thread starter Geert M
  • Start date Start date
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
 
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
 
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
 
Back
Top