1

I am looking for a way to set the processor affinity of a thread created in managed code by the System.Thread class. I see that ProcessThread has a ProcessorAffinity 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 System.Thread. The property ManagedThreadId cannot be used to identify a process thread found in the Process.Threads, it seems that the ProcessThread.Id is the id of an unmanaged thread (are they the same???).

Any suggestions would be greatly appreciated! I would have thought that this would have been easy.

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
  • 2
    Does this answer your question? [Set affinity of CPUs](https://stackoverflow.com/questions/13834588/) and [How Can I Set Processor Affinity in .NET?](https://stackoverflow.com/questions/2510593/) and [Set thread processor affinity](https://stackoverflow.com/questions/12328751/) and [How to set process affinity to all processors](https://stackoverflow.com/questions/46177649/) and [Is Core Affinity Something that We Can Safely Do in .NET?](https://stackoverflow.com/questions/50700915/) and [Why set the ProcessorAffinity for a thread?](https://stackoverflow.com/questions/18234297/) –  Aug 04 '21 at 09:35
  • Regarding the relationship between the `ProcessThread.Id` and the `Thread.ManagedThreadId`, check out this question: [Getting from ProcessThread to a managed thread](https://stackoverflow.com/questions/1749541/getting-from-processthread-to-a-managed-thread) – Theodor Zoulias Aug 04 '21 at 10:36

0 Answers0