The first thing to note is that GetCurrentTime() has been deprecated by GetTickCount(). Second, calling SetThreadPriority() with a priority greater than 11 may cause disk caches to not flush, hang the mouse, and so on.
jinzhecheng wrote:
How can I ensure those steps are not interupted?
By using a critical section (e.g., InitializeCriticalSection()). I'm not sure you actually want to do this, however. If you are simply wanting to time a section of code, GetTickCount() is the way to do this. Since Windows is not a RTOS, you'll not ever get 100% accuracy. For example, let's say that, per your watch, the code took 5 seconds to execute. However, span had a value of 6000, or 6 seconds. That means that the code was preempted for a total of 1000 ms. This is not necessarily a bad thing. It's much like weighing yourself at home on a scale that is not 100% accurate. Whether it shows you to be too heavy or too light, it doesn't matter as long as it's consistent. By comparing one weigh with another from the same scale, you can judge for yourself whether you are gaining or losing weight. Make sense?
"Take only what you need and leave the land as you found it." - Native American Proverb