Is there anyway to tell when code is executing at compile time?

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

Is there any way to check, in code, whether that code is being executed
because of a compile as opposed to being executed because someone is just
running the program?

- Don
 
Don said:
Is there any way to check, in code, whether that code is being executed
because of a compile as opposed to being executed because someone is just
running the program?

Code won't run when it's compiled. What you can do is distinguish between a
release and debug version, and you can check if a debugger is attached:

\\\
#If DEBUG Then
Console.WriteLine("Debug mode.")
#Else
Console.WriteLine("Release mode.")
#End If
///

Make sure that the option "Configuration settings" -> "Build" "Define DEBUG
constant" in the project properties is checked.


- and/or -

'System.Diagnostics.Debugger.IsAttached'
 
Hello, Don:

You can also use System.Diagnostics.Debugger.IsAttached to know if your code is being debugged.

Regards.


"Don" <[email protected]> escribió en el mensaje | Is there any way to check, in code, whether that code is being executed
| because of a compile as opposed to being executed because someone is just
| running the program?
|
| - Don
 
I've come across an instance where code is actually being executed when it
is being compiled, resulting in changes to controls on the form after a
build (see the thread titled "How to detect when items are added to
Combobox/Listbox" in this newsgroup).

I think, however, that what you are suggesting might do the trick. Thanks

- Don
 
On second thought, this won't help at all. I still want the code to execute
when the debugger is attached to the executing code. I just don't want the
code to execute when its compiling.

- Don
 
Don said:
I've come across an instance where code is actually being executed when it
is being compiled,

Honestly, you haven't.
resulting in changes to controls on the form after a build

Ah; that sounds like code in a custom control running within the
Forms Designer as you work on A.N.Other project that /uses/
that control.
Mine used to throw the odd Exception as well, causing all my
Controls on the form to disappear!

I think the DesignMode property for the inherited or User Control
is the one you're after.

HTH,
Phill W.
 

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