Freigeben über


ProcessThread.ProcessorAffinity Eigenschaft

Definition

Legt die Prozessoren fest, auf denen der zugeordnete Thread ausgeführt werden kann.

public:
 property IntPtr ProcessorAffinity {  void set(IntPtr value); };
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public IntPtr ProcessorAffinity { set; }
public IntPtr ProcessorAffinity { set; }
[System.ComponentModel.Browsable(false)]
public IntPtr ProcessorAffinity { set; }
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
member this.ProcessorAffinity : nativeint
member this.ProcessorAffinity : nativeint
[<System.ComponentModel.Browsable(false)>]
member this.ProcessorAffinity : nativeint
Public Property ProcessorAffinity As IntPtr

Eigenschaftswert

IntPtr

nativeint

Ein IntPtr Punkt auf einen Satz von Bits, von denen jeder einen Prozessor darstellt, auf dem der Thread ausgeführt werden kann.

Attribute

Ausnahmen

Die Prozessoraffinität konnte nicht festgelegt werden.

Der Prozess befindet sich auf einem Remotecomputer.

Beispiele

Das folgende Beispiel zeigt, wie die ProcessorAffinity Eigenschaft für eine Instanz von Editor auf den ersten Prozessor festgelegt wird.

using System;
using System.Diagnostics;

namespace ProcessThreadIdealProcessor
{
    class Program
    {
        static void Main(string[] args)
        {
            // Make sure there is an instance of notepad running.
            Process[] notepads = Process.GetProcessesByName("notepad");
            if (notepads.Length == 0)
                Process.Start("notepad");
            ProcessThreadCollection threads;
            //Process[] notepads;
            // Retrieve the Notepad processes.
            notepads = Process.GetProcessesByName("Notepad");
            // Get the ProcessThread collection for the first instance
            threads = notepads[0].Threads;
            // Set the properties on the first ProcessThread in the collection
            threads[0].IdealProcessor = 0;
            threads[0].ProcessorAffinity = (IntPtr)1;
        }
    }
}
Imports System.Diagnostics



Class Program
    
    Shared Sub Main(ByVal args() As String) 
        ' Make sure there is an instance of notepad running.
        Dim notepads As Process() = Process.GetProcessesByName("notepad")
        If notepads.Length = 0 Then
            Process.Start("notepad")
        End If
        Dim threads As ProcessThreadCollection
        'Process[] notepads;
        ' Retrieve the Notepad processes.
        notepads = Process.GetProcessesByName("Notepad")
        ' Get the ProcessThread collection for the first instance
        threads = notepads(0).Threads
        ' Set the properties on the first ProcessThread in the collection
        threads(0).IdealProcessor = 0
        threads(0).ProcessorAffinity = CType(1, IntPtr)
    End Sub
End Class

Hinweise

Die Prozessoraffinität eines Threads ist die Gruppe von Prozessoren, zu der sie eine Beziehung hat. Mit anderen Worten, diese können für die Ausführung geplant werden.

ProcessorAffinity stellt jeden Prozessor als Bit dar. Bit 0 stellt Prozessor 1 dar, Bit 1 stellt Prozessor 2 usw. dar. Die folgende Tabelle zeigt eine Teilmenge der möglichen ProcessorAffinity Komponenten für ein System mit vier Prozessorn.

Eigenschaftswert (hexadezimal) Gültige Prozessoren
0x0001 1
0x0002 2
0x0003 1 oder 2
0x0004 3
0x0005 1 oder 3
0x0007 1, 2 oder 3
0x000F 1, 2, 3 oder 4

Sie können auch den einzelnen, bevorzugten Prozessor für einen Thread angeben, indem Sie die IdealProcessor Eigenschaft festlegen. Ein Prozessthread kann von Prozessor zu Prozessor migrieren, wobei jede Migration den Prozessorcache neu lädt. Die Angabe eines Prozessors für einen Thread kann die Leistung bei hohen Systemlasten verbessern, indem die Anzahl der neu geladenen Prozessorcaches reduziert wird.

Gilt für:

Weitere Informationen