|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Is there anyway to tell when code is executing at compile time?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" <unkn***@oblivion.com> schrieb: Code won't run when it's compiled. What you can do is distinguish between a > 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? 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/> 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/> > 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" <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 Honestly, you haven't.> is being compiled, > resulting in changes to controls on the form after a build Ah; that sounds like code in a custom control running within theForms 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. 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. 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. > > 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 |
|||||||||||||||||||||||