Debug Regions

  • Thread starter Thread starter JZ
  • Start date Start date
J

JZ

Hi,

Is there anyway to mark a block of code so that it will only run in debug
mode?

Like a # debug region ?

Thanks,
 
#If Debug = true then
'this compiles in debug mode only
#End If

hth
guy
 
JZ,
In addition to "#if DEBUG" as the other suggest, check out
System.Diagnostics.ConditionalAttribute. It allows to define a routine that
will only be called in a specific build.

<Conditional("DEBUG")> _
Public Sub CalledOnlyInDebugBuilds()

End Sub

<Conditional("TRACE")> _
Public Sub CalledOnlyInTraceBuilds()

End Sub

If the DEBUG or TRACE conditional compilation constants are not defined
(such as DEBUG in Release builds) the above calls are treated as nops.

Its how Debug.WriteLine & Trace.WriteLine are implemented.

Hope this helps
Jay
 
JZ said:
Is there anyway to mark a block of code so that it will only run in
debug mode?

Like a # debug region ?

\\\
#If DEBUG Then
...
#Else
...
#End If
///

In the project properties, make sure the checkbox that defines the
'DEBUG' constant is checked (this checkbox should be checked by default).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top