8

I have a quad core CPU, and lets say I always want to start a Thread on the second core.

Is that possible in C#?

3

3 Answers 3

9

Yes. Check out ProcessorAffinity for Windows or SetProcessorAffinity for XBox XNA.

This is also discussed on another Stackoverflow question.

Sign up to request clarification or add additional context in comments.

Comments

8

Yes, take a look at the ProcessorAffinity property for the thread.

Comments

2

Set ProcessorAffinity of the process:

0x0001 = 0000 0001 - run on 1st core ↑ 0x0002 = 0000 0010 - run on 2nd core ↑ 0x0003 = 0000 0011 - run on 1st and 2nd core ↑↑ 0x0004 = 0000 0100 - run on 3rd core ↑ 

Simple code:

using (var process = Process.GetCurrentProcess()) { // only run on core number 1 process.ProcessorAffinity = (IntPtr) 0x0001; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.