title: How to wait until remote .NET debugger attached
body: <p>Today I ran into a problem were I needed to remote-debug a program.  The program was launched from another system, so I really don't have an opportunity to interact with it on the command line.  I could change its source easily though.</p>
  
  <p>What I needed to happen was for the program to start normally, and then wait for me to attach to it with a debugger. I couldn't come up with a way to do it that made me happy.  I did find the bug, but without the help of the debugger.</p>
  
  <pre><code>while(true) { }
  </code></pre>
  
  <p>Kept the process alive, and then I could "set next statement" with the debugger, but it seemed awkward and rude.</p>
  
  <pre><code>Console.ReadLine();
  </code></pre>
  
  <p>Seemed odd to type since there wasn't actually a Console for me to press <strong>enter</strong> at.  (It didn't work, either.  Set next statement and then run takes you back into the ReadLine() wait.)</p>
  
  <p>So what kind of code can I insert into a .NET/CLR/C# program that says "wait here until I can attach with a debugger"?</p>