title: How to set the processor affinity of a managed thread?
body: <p>I am looking for a way to set the processor affinity of a thread created in managed code by the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.threading.thread?view=net-5.0" rel="nofollow noreferrer">System.Thread</a> class.  I see that <a href="https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processthread?view=net-5.0" rel="nofollow noreferrer">ProcessThread</a> has a <code>ProcessorAffinity</code> property that I understand can be used to set a thread's affinity, however, I do not see a straightforward way to set the affinity of a <code>System.Thread</code>. The property <code>ManagedThreadId</code> cannot be used to identify a process thread found in the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.threads?view=net-5.0" rel="nofollow noreferrer">Process.Threads</a>, it seems that the <code>ProcessThread.Id</code> is the id of an unmanaged thread (are they the same???).</p>
  <p>Any suggestions would be greatly appreciated! I would have thought that this would have been easy.</p>