Detecting if Code is Running from the IDE

Provided by the FMS Development Team

During development, you may find that you need your code to determine if is running from the IDE or standalone.

Unlike previous Microsoft development platforms like VB 6, Visual Studio .NET assemblies don’t have a different “mode” when running from the IDE or from the command line. This makes it difficult to figure out how if an assembly is running from the IDE (i.e. from within Visual Studio .NET).

There are several methods of accomplishing this. The simplest is to use the System.Diagnostics.Debugger.IsAttached property to determine if there is a .NET debugger attached to the currently executing code. If there is, you can assume the code is running from the IDE:

C#

if (Debugger.IsAttached)
{
    // Since there is a debugger attached, assume we are running from the IDE
}
else
{
    // Assume we aren't running from the IDE
}

Visual Basic .NET

If Debugger.IsAttached Then
    ' Since there is a debugger attached, assume we are running from the IDE
Else
    ' Assume we aren't running from the IDE
End If

User Controls in Runtime Mode

There are also issues with creating your own controls. In some cases, you have code that should not execute in design mode, but should in run mode. In this case, simply use the DesignMode property of the object:

C#

if (this.DesignMode())
{
    // The component is in design mode
}
else
{
    // The component is in run mode
}

Visual Basic .NET

If Me.DesignMode Then
    ' The component is in design mode
Else
    ' The component is in run mode
End If

Additional Resources

 

 

Thank you! Thank you! I just finished reading this document, which was part of a link in the recent Buzz newsletter. I have printed it for others to read, especially those skeptical on the powers of Access and its capabilities.

Darren D.


View all FMS products for Microsoft Access All Our Microsoft Access Products

 

 

Free Product Catalog from FMS