Previous versions of Visual Basic made it easy to figure out whether you were running your application through the IDE (Integrated Development Environment). It simply allowed you to check which “mode” your application was in. VB.NET, however, isn’t quite as easy-going.
The most common method of figuring out whether the application is running in
the .NET IDE is to check the System.Diagnostics.Debugger.IsAttached
property
to determine whether if a debugger is attached to the currently executing code.
If so, you can safely assume your code is running from within the IDE.
If you’re designing your own controls, you might also run into the situation
where your code is running in design mode—while you only want it to execute
during ‘full’ runtime. In this situation, simply check the DesignMode
property of your component (that is, from inside your control: Me.DesignMode
).
If it returns True, you’re running in the IDE—so cut your code
short.
Simple solutions to common questions, and definitely worth remembering.
Comments