Besides System.Diagnostics.Debugger.IsAttached, there is also a
precompiler constant / statement you can use. Since this is a
precompiler option, it can improve performance in the "live"
application (removes the actual if...then check for
Debugger.IsAttached). It also allows you to toggle code outside of
methods, such as switching variable values based on environment:
#If DEBUG Then
Private foo As String = "debug"
#Else
Private foo as String = "production"
#End If