0

I have the following code (inherited from a contractor):

public partial class StoredProcedures  
{  
    #if NO_THREAD      
        readonly static String version = "XXXX, Version 1.02, Apr/29/2010";
    #else 
        readonly static String version = "XXXX, Version 0.93, Dec/21/2006";
    #endif

I can't seem to find NO_THREAD anywhere else. This is code that compiles and installs as a SQL assembly. Is it something special or am I missing something simple?

6
  • 2
    Seems quite weird to me. Which line is grayed out when you look at that from within Visual Studio? Commented Aug 28, 2012 at 22:54
  • 3
    Have you looked in the project properties on the build tab? NO_THREAD looks like a conditional compilation symbol. Commented Aug 28, 2012 at 22:56
  • oh okay, the bottom line is grayed out, meaning the first is run? i'll look at project properties now Commented Aug 28, 2012 at 22:58
  • @chris - The name chosen for the symbol does not seem very useful. I assume that some portion of the older version is multi-threaded? Commented Aug 28, 2012 at 23:00
  • 1
    Seems like a hack to me, probably for maintenance. For instance, if the previous maintainers found a bug in the 2006 version of the code, they could compile without the NO_THREAD preprocessor definition. This is why maintenance branches make sense. Or, it could be for compiling to target SQL Server 2005 and SQL Server 2008 in which case NO_THREAD maintains support for one and not the other. Commented Aug 28, 2012 at 23:03

6 Answers 6

4

Try to check Project Properties->Build->General->Conditional compilation symbols for all Build configurations which you have for the project, It may be there.

Sign up to request clarification or add additional context in comments.

Comments

1

Look for a #define statement. See the docs for #if preprocessor conditionals : http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx

Comments

1

If you can't find a

define #NO_THREAD

Anywhere in the code, then it's probably because the contractor was defining the symbol by passing the /define compiler option.

See here for more details (typing from a cell, sorry for the format):

http://msdn.microsoft.com/en-us/library/0feaad6z.aspx

Comments

0

you should probably have a look at the c# pre-processor directives

No_Thread here is a symbol which can be defined by using #define No_Thread and when #define No_Thread is present then #if NO_THREAD will result in true and at compile time readonly static String version = "XXXX, Version 1.02, Apr/29/2010"; this statement will be compiled otherwise the next statement will be compiled.

this is generally used to differentiate between debug and release versions. have you noticed there are 2 versions in VS when you create a new project. if you write something like this somewhere in you code

 #if DEBUG
 Console.WriteLine("DEBUG VERSION");
 #endif

then the string "DEBUG VERSION" would only be printed on the console when the project is in debug mode because the VS inserts a symbol DEBUG if you manually do it using the #define pre-processor then too this line would be compiled

Comments

0

NO_THREAD is a symbol for conditional compilation.

It can come from, #define NO_THREAD, from the project file, or from the nant file (or whatever method you use for building).

If it's defined, the first line of code is counted as part of the C# code. If it isn't, then the second is.

If that's the sole occurence, I'd say it was a hangover from something removed, but if you're uesd to using visual studio to build, then make sure there isn't a build file for nant in case the previous developer used that instead.

Comments

0

This is a conditional compilation symbol. In Visual Studio 2010, these appear on the Build page of your Project Properties in the Conditional compilation symbols text box. Probably one of your Configuration Manager configurations either contains this symbol or has at some point in the past. Presumably, there is another #if somewhere that disables a block of code that uses multiple threads if the NO_THREAD symbol is present.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.