Home All Groups Group Topic Archive Search About

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

Author
13 Apr 2005 3:19 PM
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

Author
13 Apr 2005 4:22 PM
Herfried K. Wagner [MVP]
"Don" <unkn***@oblivion.com> schrieb:
> 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'

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
13 Apr 2005 7:40 PM
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


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OUHOyTEQFHA.164@TK2MSFTNGP12.phx.gbl...
> "Don" <unkn***@oblivion.com> schrieb:
> > 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'
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
Author
13 Apr 2005 7:47 PM
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
Author
14 Apr 2005 11:16 AM
Phill. W
"Don" <unkn***@oblivion.com> wrote in message
news:CAe7e.1002970$8l.630672@pd7tw1no...
> 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.
Author
15 Apr 2005 6:21 PM
Don
Thanks!  I think that property successfully allows me to make sure the
combobox doesn't add extra blank lines after a compile.


Show quoteHide quote
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:d3lj3h$1k9$1@yarrow.open.ac.uk...
> "Don" <unkn***@oblivion.com> wrote in message
> news:CAe7e.1002970$8l.630672@pd7tw1no...
>
> I think the DesignMode property for the inherited or User Control
> is the one you're after.
Author
15 Apr 2005 6:27 PM
Don
I spoke to soon.  At first it appeared to have worked, but after further
testing it didn't work.


"Don" <unkn***@oblivion.com> wrote in message
news:KCT7e.1026911$8l.560654@pd7tw1no...
Show quoteHide quote
> Thanks!  I think that property successfully allows me to make sure the
> combobox doesn't add extra blank lines after a compile.
>
>
> "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
> news:d3lj3h$1k9$1@yarrow.open.ac.uk...
> > "Don" <unkn***@oblivion.com> wrote in message
> > news:CAe7e.1002970$8l.630672@pd7tw1no...
> >
> > I think the DesignMode property for the inherited or User Control
> > is the one you're after.
>
>
Author
13 Apr 2005 5:59 PM
José_Manuel_Agüero
Hello, Don:

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

Regards.


Show quoteHide quote
"Don" <unkn***@oblivion.com> escribió en el mensaje news:2Ma7e.1000710$8l.410355@pd7tw1no...
| 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