Does anybody know how I can put a method running in a seperate thread into a wait loop without consuming my CPU? I have created a method called ProcessJobs. This method runs on a seperate thread and waits for a flag to be set true. Upon the flag being set to true, tasks are performed and the flag is reset to false. The problem I am having is that while waiting for the flag to be set to true my CPU utilisation is high slowing my computer down even though my application in reality is doing nothing other than loop. Does any body know how I could get around this?
I use the following code to start the method
This is the method code
I use the following code to start the method
VB.NET:
m_ProcessThread = New Threading.Thread(AddressOf ProcessJobs)
m_ProcessThread.Name = "Process Jobs"
m_ProcessThread.Start()
VB.NET:
private sub ProcessJobs
while not m_Cancelled
while not m_StartProcess
'loop until we get a start signal
loop
'Perform some actions and wait for the next signal
'Reset the start flag
m_StartProcess=False
loop
end sub