There are times where you just can’t manually attach the Visual Studio debugger to your code. Like when you’re trying to debug Sharepoint feature events (FeatureActivated, FeatureDeactivating, etc.) when Visual Studio is deploying your SharePoint project.
For those situations you can use this line of code to attach Visual Studio to your process.
System.Diagnostics.Debugger.Launch();
Just make sure to remove it before you ship your software.