Those who prefer reading this site through RSS now can also subscribe for updates to .NET Tips & Tricks Community.
Actually you can use this trick every time when:
So the problem is that you can't simply attach the Visual Studio debugger to the process as there isn't one to attach to until after you start the process. However, once you start the process if you have a bug such as an exception in the process's initialization you won't get the debugger attached to the process before it's too late.
Calling Debugger.Launch() or Debugger.Break() in your code allow you to debug such problems. This methods pop up the following screen asking you which instance of the debugger it should use to debug the application.