ProcessThread::ProcessorAffinity Property

 

Sets the processors on which the associated thread can run.

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)

public:
[BrowsableAttribute(false)]
property IntPtr ProcessorAffinity {
	void set(IntPtr value);
}

Property Value

Type: System::IntPtr

An IntPtr that points to a set of bits, each of which represents a processor that the thread can run on.

Exception Condition
Win32Exception

The processor affinity could not be set.

PlatformNotSupportedException

The platform is Windows 98 or Windows Millennium Edition.

NotSupportedException

The process is on a remote computer.

The processor affinity of a thread is the set of processors it has a relationship to. In other words, those it can be scheduled to run on.

ProcessorAffinity represents each processor as a bit. Bit 0 represents processor one, bit 1 represents processor two, and so on. The following table shows a subset of the possible ProcessorAffinity for a four-processor system.

Property value (in hexadecimal)

Valid processors

0x0001

1

0x0002

2

0x0003

1 or 2

0x0004

3

0x0005

1 or 3

0x0007

1, 2, or 3

0x000F

1, 2, 3, or 4

You can also specify the single, preferred processor for a thread by setting the IdealProcessor property. A process thread can migrate from processor to processor, with each migration reloading the processor cache. Specifying a processor for a thread can improve performance under heavy system loads by reducing the number of times the processor cache is reloaded.

The following example shows how to set the ProcessorAffinity property for an instance of Notepad to the first processor.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: