KiloWatt.Runtime.Support.ThreadPoolComponent.ThreadPoolComponent C# (CSharp) Method

ThreadPoolComponent() public method

Create the ThreadPoolComponent in your application constructor, and add it to your Components collection. The ThreadPool will deliver any completed tasks first in the update order. On Xbox, creates 3 threads. On PC, creates one or more threads, depending on the number of CPU cores. Always creates at least one thread. The thread tasks are assumed to be computationally expensive, so more threads than there are CPU cores is not recommended.
public ThreadPoolComponent ( Microsoft.Xna.Framework.Game game ) : System
game Microsoft.Xna.Framework.Game Your game instance.
return System
        public ThreadPoolComponent(Game game)
            : base(game)
        {
            #if XBOX360
              int[] HardwareThread = new int[] { 3, 4, 5 };
              nThreads_ = 3;
              for (int i = 0; i != nThreads_; ++i)
              {
            int hwt = HardwareThread[i];
            Thread t = new System.Threading.Thread(new ThreadStart(
            delegate () {
              Thread.CurrentThread.SetProcessorAffinity(new int [] { hwt });
              this.ThreadFunc();
            }));
            t.Start();
              }
            #else
              //  hoaky but reasonable way of getting the number of processors in .NET
              nThreads_ = System.Environment.ProcessorCount;
              for (int i = 0; i != nThreads_; ++i)
              {
            Thread t = new System.Threading.Thread(new ThreadStart(this.ThreadFunc));
            t.Start();
              }
            #endif
              UpdateOrder = Int32.MinValue;
        }