ProcessThread.ProcessorAffinity Właściwość

Definicja

Ustawia procesory, na których można uruchomić skojarzony wątek.

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

Wartość właściwości

IntPtr

nativeint

Element IntPtr wskazujący zestaw bitów, z których każdy reprezentuje procesor, na którym można uruchomić wątek.

Atrybuty

Wyjątki

Nie można ustawić koligacji procesora.

Proces jest na komputerze zdalnym.

Przykłady

W poniższym przykładzie pokazano, jak ustawić ProcessorAffinity właściwość dla wystąpienia Notatnika na pierwszy procesor.

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

Uwagi

Koligacja procesora wątku to zestaw procesorów, z których ma relację. Innymi słowy, można je zaplanować do uruchomienia.

ProcessorAffinity reprezentuje każdy procesor jako nieco. Bit 0 reprezentuje procesor jeden, bit 1 reprezentuje procesor dwa i tak dalej. W poniższej tabeli przedstawiono podzbiór możliwego ProcessorAffinity systemu z czterema procesorami.

Wartość właściwości (w szesnastkowym) Prawidłowe procesory
0x0001 1
0x0002 2
0x0003 1 lub 2
0x0004 3
0x0005 1 lub 3
0x0007 1, 2 lub 3
0x000F 1, 2, 3 lub 4

Można również określić pojedynczy, preferowany procesor dla wątku IdealProcessor , ustawiając właściwość . Wątek procesu może migrować z procesora do procesora, a każda migracja ponownie ładuje pamięć podręczną procesora. Określenie procesora dla wątku może zwiększyć wydajność w przypadku dużych obciążeń systemowych przez zmniejszenie liczby ponownych ładowań pamięci podręcznej procesora.

Dotyczy

Zobacz też