By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,737 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,737 IT Pros & Developers. It's quick & easy.

How to check Thread is terminated?

P: n/a
Hi, I have a thread where it will do a Do While..Loop and check the
blnCancel boolean in every loop. If blnCancel is True, then the loop will
exit and the Thread should be terminated naturally. But there is some
scenario where the program stuck somewhere in the Do While..Loop and and
unable to exit the loop. In this case, I would need to abort the thread all
together. But I have some problem in doing this, here is how I did:

Private Sub DoCancel()
blnCancel = True

If th.IsAlive Then
If th.Join(10000) = False Then <------Prolem: Always
return False.
th.Abort()
End If
End If
End Sub

The th.Join (miliseconds) always return false even I know the thread should
have terminated "normally". How can I solve this? Please advice. Thanks.
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sleepyant <no@nono.no> wrote:
Hi, I have a thread where it will do a Do While..Loop and check the
blnCancel boolean in every loop. If blnCancel is True, then the loop will
exit and the Thread should be terminated naturally. But there is some
scenario where the program stuck somewhere in the Do While..Loop and and
unable to exit the loop. In this case, I would need to abort the thread all
together. But I have some problem in doing this, here is how I did:

Private Sub DoCancel()
blnCancel = True

If th.IsAlive Then
If th.Join(10000) = False Then <------Prolem: Always
return False.
th.Abort()
End If
End If
End Sub

The th.Join (miliseconds) always return false even I know the thread should
have terminated "normally". How can I solve this? Please advice. Thanks.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Note that just setting a boolean field isn't a thread-safe way of
indicating that a thread should stop, unless the field is volatile.
Otherwise, you need locking.
See http://www.pobox.com/~skeet/csharp/t...shutdown.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.