Free Resources from FMS

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.

 

Free Catalog

 

Detecting if Code is Running from the IDE

Provided by: Dan Haught, FMS Executive Vice President

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, .NET assemblies don’t have a different “mode” when running from the IDE or from the command line. This can make it difficult to figure out how to determine 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 = true)

      {

            // 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() = true)

      {

            // 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

 

Return to the tips page