title: What is the best way to attach a debugger to a process in VC++ at just the right point in time?
body: <p>When debugging, sometimes you need to attach an already running process instead of just starting the application in a debugger. </p>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>Guarding the Sleep or message box with an <code>#ifdef _DEBUG</code> is one way, but I'm wondering if there is a better way. </p>
  
  <p>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)</p>