Search code examples
c#multithreadingprocessor

How do I find the processor on which my thread is running in C#?


How do I find the processor on which my thread is running in C#?


Solution

  • This is not necessarily a constant - the thread could be scheduled onto different cores across its lifetime. You can set affinity masks to tie a particular thread to a particular CPU if you want to. See the API docs for Thread.BeginThreadAffinity for more details on what can be done within .Net.