Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Process.ProcessorAffinity Property

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

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

public IntPtr ProcessorAffinity { get; set; }
/** @property */
public IntPtr get_ProcessorAffinity ()

/** @property */
public void set_ProcessorAffinity (IntPtr value)

public function get ProcessorAffinity () : IntPtr

public function set ProcessorAffinity (value : IntPtr)

Not applicable.

Property Value

A bitmask representing the processors that the threads in the associated process can run on. The default depends on the number of processors on the computer. The default value is 2 n -1, where n is the number of processors.

Exception typeCondition

Win32Exception

ProcessorAffinity information could not be set or retrieved from the associated process resource.

-or-

The process identifier or process handle is zero. (The process has not been started.)

NotSupportedException

You are attempting to access the ProcessorAffinity property for a process that is running on a remote computer. This property is available only for processes that are running on the local computer.

InvalidOperationException

The process Id was not available.

-or-

The process has exited.

In Windows 2000 and later, 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 one, bit 1 is processor two, and so forth. If you set a bit to the value 1, the corresponding processor is selected for thread assignment. When you set the ProcessorAffinity value to zero, the operating system's scheduling algorithms set the thread's affinity. When the ProcessorAffinity value is set to any nonzero value, the value is interpreted as a bitmask that specifies those processors eligible for selection.

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

Bitmask

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

  • LinkDemand  for full trust for the immediate caller. This member cannot be used by partially trusted code.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft