C
Chris Dunaway
According to the docs, calling Thread.Sleep(0) causes the thread to be
"suspended to allow other waiting threads to execute."
What happens if I call Thread.Sleep(500)? Do other threads not get a
chance to execute during this time? What is the difference between the
two?
I have code that runs in a loop like this:
Dim dResetTime As DateTime = DateTime.Now
Do
If DateTime.Now >= dResetTime Then
DoWork()
dResetTime = dResetTime.AddSeconds(iNumSeconds)
End If
Threading.Thread.Sleep(500)
Loop Until bStopRequest
Would I be better off using Threading.Thread.Sleep(0) in this instance?
How would this affect CPU load? I want the DoWork method to run with
an interval of iNumSeconds but I want to be able to stop the loop by
setting the bStopRequest to True.
Is this an appropriate to handle this? I don't want the loop to tax
the CPU.
Thanks for any insight or suggestions.
Chris
"suspended to allow other waiting threads to execute."
What happens if I call Thread.Sleep(500)? Do other threads not get a
chance to execute during this time? What is the difference between the
two?
I have code that runs in a loop like this:
Dim dResetTime As DateTime = DateTime.Now
Do
If DateTime.Now >= dResetTime Then
DoWork()
dResetTime = dResetTime.AddSeconds(iNumSeconds)
End If
Threading.Thread.Sleep(500)
Loop Until bStopRequest
Would I be better off using Threading.Thread.Sleep(0) in this instance?
How would this affect CPU load? I want the DoWork method to run with
an interval of iNumSeconds but I want to be able to stop the loop by
setting the bStopRequest to True.
Is this an appropriate to handle this? I don't want the loop to tax
the CPU.
Thanks for any insight or suggestions.
Chris