473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
Nov 21 '05 #1
7 1193
"Don" <un*****@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/>

Nov 21 '05 #2
Hello, Don:

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

Regards.
"Don" <un*****@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

Nov 21 '05 #3
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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OU*************@TK2MSFTNGP12.phx.gbl...
"Don" <un*****@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/>

Nov 21 '05 #4
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
Nov 21 '05 #5
"Don" <un*****@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.
Nov 21 '05 #6
Don
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:d3**********@yarrow.open.ac.uk...
"Don" <un*****@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.

Nov 21 '05 #7
Don
I spoke to soon. At first it appeared to have worked, but after further
testing it didn't work.
"Don" <un*****@oblivion.com> wrote in message
news:KCT7e.1026911$8l.560654@pd7tw1no...
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:d3**********@yarrow.open.ac.uk...
"Don" <un*****@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.


Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Michael Strorm | last post by:
Hi! I posted a message a while back asking for project suggestions, and decided to go with the idea of creating an adventure game (although it was never intended to be a 'proper' game, rather an...
2
by: Richard Bell | last post by:
Newbie question ... please respond to group I'm trying to open/navigate to a url. How can I tell when the page is fully loaded? Testing suggest that window.open returns before the page is...
8
by: Harvey Twyman | last post by:
I have code written under the CCS 'C' Compiler to run on a PIC microcontroller. Code Extract: ------------------------------- char a,b,c; ------------------------------- c = ( a == b );...
13
by: Skybuck Flying | last post by:
Hi, I would like to split main.c which contains all code into the following Step 1. Machine.h Step 2. drand.h and drand.c Step 3. nrand.h and nrand.c Main.c then only contains some test...
29
by: Roy Gourgi | last post by:
Hi, I am new to C#. I have the same time scheduling program written in C++ and it is 5 times faster than my version in C#. Why is it so slow as I thought that C# was only a little slower than...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
8
by: lovecreatesbea... | last post by:
K&R 2, sec 2.4 says: If the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, ... . "Non-automatic variables are...
0
by: Gordon Fraser | last post by:
Hi, I'm trying to parse Python code to an AST, apply some changes to the AST and then compile and run the AST, but I'm running into problems when trying to evaluate/execute the resulting code...
0
by: Orestis Markou | last post by:
Have you tried passing in empty dicts for globals and locals? I think that the defaults will be the *current* globals and locals, and then of course your namespace is broken... On Tue, Oct 7,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.