Currently, the code in the threads Run() function looks something like this...
Code:
while(!m_bKill)
{
while(!m_bRunning) { }
CSingleLock lock(&m_mMutex, TRUE);
if(lock.IsLocked())
{
if(m_pNote)
{
m_pNote->PostMessage(WM_AUTOSAVE);
}
else
{
m_bRunning = FALSE;
lock.Unlock();
}
while(m_bRunning) { }
lock.Unlock();
}
else
{
m_bRunning = FALSE;
}
}
return 0;
There is a timer elsewhere that flips m_bRunning to TRUE causing the WM_AUTOSAVE message to be sent. The function that handles that sets m_bRunning back to FALSE.
This is a pretty ugly setup and the while-loops for m_bRunning are clearly not ideal as they just sit and spin on the CPU.
How else could I execute this code and then put the thread to sleep for a defined period of time before executing again? I've read in numerous places that Sleep() is not a very good thing to do in UI threads for some reason...
Thanks for your help
