Debug Mode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick K.

    Debug Mode

    I want a line of code to execute only if it is in debug mode, is there a way
    to do this in .Net/C#?



  • Sherif ElMetainy

    #2
    Re: Debug Mode

    Hello

    If you want conditional compilation (i.e. the code would be included only in
    the debug version of the application) use the following

    #if DEBUG
    // your debug code here
    #else
    // code for release version
    #endif

    If you want code to execute when a debugger is attached to the process

    if(System.Diagn ostics.Debugger .IsAttached)
    {
    // Your code here
    }

    Best regards,
    Sherif

    "Nick K." <nick@bogus.com > wrote in message
    news:#17aG08iEH A.644@tk2msftng p13.phx.gbl...[color=blue]
    > I want a line of code to execute only if it is in debug mode, is there a[/color]
    way[color=blue]
    > to do this in .Net/C#?
    >
    >
    >[/color]


    Comment

    • Scott Allen

      #3
      Re: Debug Mode

      And one more:

      Don't forget the System.Diagnost ics.Conditional Attribute class.

      [Conditional("CO NDITION1")]
      public static void Method1()
      {
      Debug.Write("Me thod1 - DEBUG and CONDITION1 are specified\n");
      Trace.Write("Me thod1 - TRACE and CONDITION1 are specified\n");
      }


      --
      Scott


      On Thu, 26 Aug 2004 18:31:53 -0600, "Nick K." <nick@bogus.com > wrote:
      [color=blue]
      >I want a line of code to execute only if it is in debug mode, is there a way
      >to do this in .Net/C#?
      >
      >[/color]

      Comment

      Working...