[Note: Today's article is courtesy of Raymond Chen, graciously covering for Alex while he is on vacation this week]

Hi, everybody. It's me, Raymond Chen, author of The Old New Thing. A bunch of friends and I bought the copy of Small Business Server that runs this site, so we feel partly responsible for the pain and suffering all you readers out there have had to endure for nearly two years now. If it weren't for us, you wouldn't have had the urge to gouge your own eyes out after reading The Brillant Paula Bean. If I were a better person, I'd apologize, but instead, I'm just going to prolong the torture.

Today's example is not the strangest way to suspend execution for 60 seconds, but it's definitely a finalist ...

void ExitThreadAfterDelay()
 HANDLE hTimer = CreateWaitableTimer(0, FALSE, 0);
 if (hTimer) {
  LARGE_INTEGER SixtySeconds;
  SixtySeconds.QuadPart = -600000000L;
  if (SetWaitableTimer(hTimer, &SixtySeconds, 0, NULL, NULL, FALSE)) {
   if (WaitForSingleObject(hTimer, INFINITE) == WAIT_OBJECT_0) {

First, the function creates a "waitable timer" object and tells it to fire in sixty seconds. Then it waits indefinitely for the object to fire and exits the thread. Apparently there was some contest to see who can go the longest without calling the Sleep function. That's the only explanation I could come up with. And as you might expect from going without sleep, a few bugs snuck in along the way.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!