1

Well I'm trying to deploy my first ever Xbox 360 XNA game which uses multithreading, and I'm trying to put a thread on another hardware thread using the Thread.CurrentThread.SetProcessorAffinity() function, like so:

#if XBOX360

        Thread.CurrentThread.SetProcessorAffinity(new int[] { xbox360UpdateThread });
        Thread.CurrentThread.IsBackground = true;
#endif

I have also tried this:

#if XBOX

        Thread.CurrentThread.SetProcessorAffinity(new int[] { xbox360UpdateThread });
        Thread.CurrentThread.IsBackground = true;
#endif

The compiler is giving me problem with the brackets somewhere in the first instruction above .. In VS2008, all the brackets are underlined with those red markers and I get the following errors:

error CS1519: Invalid token '(' in class, struct, or interface member declaration
error CS1519: Invalid token '{' in class, struct, or interface member declaration
error CS1519: Invalid token '}' in class, struct, or interface member declaration
error CS0116: A namespace does not directly contain members such as fields or methods

if I hide the entire threading directive above, and I compile and run my game on the Xbox 360 .. Only this threading directive is causing a problem ..

Anyone know what am I doing wrong ? I'm using XNA 3.1, not 4.0 ..

Zach Johnson
  • 23,678
  • 6
  • 69
  • 86
Ahmad
  • 12,886
  • 30
  • 93
  • 146
  • 1
    Where are you putting this code? From the errors you're getting it looks like you might have it in a namespace or class declaration, it needs to go in a method body. – Phil Lamb Dec 08 '10 at 21:06
  • Where are those lines placed? Inside a method or just inside a class? – Lasse V. Karlsen Dec 08 '10 at 21:07
  • Got it .. My mistake .. I thought I put it in the Update function :P .. Thanks, this correct it ! – Ahmad Dec 08 '10 at 21:10

1 Answers1

2

I would do the following:

#if XBOX360 
    // We can not use threads 0 or 2   
    int[] xbox360UpdateThread = new int[] { 4 }; 
    Thread.CurrentThread.SetProcessorAffinity(xbox360UpdateThread); 
    Thread.CurrentThread.IsBackground = true; 
#endif 
Neil Knight
  • 47,437
  • 25
  • 129
  • 188