Thread: interlock exchange issue

  1. #1
    Registered User
    Join Date
    May 2006

    interlock exchange issue

    Hello everyone,

    How to fix the compile error when interlock exchange a bool type variable?

        public static void Main()
            bool b = false;
            // error CS0452: The type 'bool' must be a reference type in order to use it as parameter
            // 'T' in the generic type or method 'System.Threading.Interlocked.Exchange<T>(ref T, T)'
            bool a = Interlocked.Exchange(ref b, true);

    thanks in advance,

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    The MSDN examples state that you should be using an int instead. While this is also a non-referencetype, there are overloads of Exchange for int.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. MS Exchange Calender access
    By maes in forum Windows Programming
    Replies: 2
    Last Post: 07-17-2004, 02:17 AM
  3. Recovery Exchange 2000 Public folders?!?!
    By gicio in forum Tech Board
    Replies: 4
    Last Post: 10-01-2003, 07:48 AM
  4. Replies: 8
    Last Post: 09-22-2003, 01:31 PM
  5. Connect 2 domains together (with Windows 2003 and Exchange 2003)?!?!??
    By gicio in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-01-2003, 07:02 PM