NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Process.ProcessorAffinity

Gets or sets which processors the threads in this process can be scheduled to run on.

[Visual Basic]
Public Property ProcessorAffinity As Integer
[C#]
public int ProcessorAffinity {get; set;}
[C++]
public: __property int get_ProcessorAffinity();
public: __property void set_ProcessorAffinity(int);
[JScript]
public function get ProcessorAffinity() : int;
public function set ProcessorAffinity(int);

Property Value

A bit mask representing the processors that the threads in the associated process can run on. The default is 0.

Exceptions

Exception Type Condition
Win32Exception ProcessorAffinity information could not be set or retrieved from the associated process resource.

-or-

The process ID or process handle is 0. (The process has not been started.)

SystemException The process Id was not available.

-or-

The process has exited.

Remarks

In Windows 2000, a thread in a process can migrate from processor to processor, with each migration reloading the processor cache. Under heavy system loads, specifying which processor should run a specific thread can improve performance by reducing the number of times the processor cache is reloaded. The association between a processor and a thread is called the processor affinity.

Each processor is represented as a bit: bit 0 is processor 1, bit 1 is processor 2, and so forth. If you set a bit representing a processor to 1, that processor is selected for thread assignment. When you set ProcessorAffinity to 0, the operating system's scheduling algorithms set the thread's affinity. When the ProcessorAffinity is set to any non-zero value, the value is interpreted as a bit mask that specifies those processors eligible for selection.

The following table shows a selection of ProcessorAffinity values for an eight-processor system.

Bit Mask Binary Value Eligible Processors
0x0001 00000000 00000001 1
0x0003 00000000 00000011 1 and 2
0x0007 00000000 00000111 1, 2 and 3
0x0009 00000000 00001001 1 and 4
0x007F 00000000 01111111 1, 2, 3, 4, 5, 6 and 7

See Also

Process Class | Process Members | System.Diagnostics Namespace