When debugging, sometimes you need to attach an already running process instead of just starting the application in a debugger.
It's common for myself to put in a Sleep() or MessageBox call, so that it's easier to attach a debugger. I worry that some of these may be committed eventually to source control.
What is the best thing to do to avoid this situation while still delaying enough time so that you can attach your debugger to a running process?
Guarding the Sleep or message box with an #ifdef _DEBUG
is one way, but I'm wondering if there is a better way.
With a Sleep you also have the problem that you may not attach in time. With a MessageBox you have the problem that you may be remotely debugging, or debugging a process that has no visible GUI (example running as a service on Vista)