using System.Threading; ... Thread t = new Thread(MyMethod); t.Start(); // set affinity to processor 1 t.BeginThreadAffinity(1);
using System.Threading; ... Thread t = new Thread(MyMethod); t.Start(); // save the current affinity IntPtr affinity = t.BeginThreadAffinity(); // set affinity to processor 1 t.BeginThreadAffinity(1); // do some work... // restore original affinity t.EndThreadAffinity(affinity);In this example, the current thread affinity is saved and then changed to processor 1. After doing some work, the original affinity is restored. The BeginThreadAffinity method is part of the System.Threading.Thread class in the .NET Framework.