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...