I have a very difficult time focusing on what I'm doing (programming-wise) when something (compilation, startup time, etc.) takes more than just a few seconds.  Anecdotally it seems that threshold is about 10 seconds (and I recall reading about study that said the same thing, though I can't find it now).  So what typically happens is I make a change and then run the program to test it.  That takes about 30 seconds, so I start reading something else, and before I know it 20 minutes have passed, and then it takes (if I'm lucky!) another 10+ minutes to deal with the context switch to getting back into programming.

It's not an exaggeration to say that some things that should take me minutes literally take hours to complete.  

I'm very curious about what other programmers do to combat this tendency (or if I'm unique and they don't have this tendency?).  Suggestions of any type at all are welcome - anything from "sit on your hands after hitting the compile button", to mental tricks, to "if it takes 30 seconds to start up something to test a change, then something's wrong with your development process!"

I wrote a little commandline utility called 'alert' which will cause the computer to beep / play a sound / etc.  Then, when I have a lengthy command to run such as a make, I run make; alert.  Where I can, I will also have it take an argument so it makes a different sound depending on the argument.  Thus I can do make; alert $? and I'll know a) the build is done, and b) it passed or failed.  You don't have to be that fancy with it; just an echo -e "\a" can be enough.

If you wanted to get really fancy/annoying, use some text-to-speech package and trigger a dialog popup.

The main idea here is to interrupt your distraction as soon as the work-related task completes.
