ProcessThread.ProcessorAffinity Egenskap

Definition

Anger de processorer som den associerade tråden kan köras på.

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

Egenskapsvärde

IntPtr

nativeint

En IntPtr som pekar på en uppsättning bitar som var och en representerar en processor som tråden kan köras på.

Attribut

Undantag

Det gick inte att ange processortillhörigheten.

Processen finns på en fjärrdator.

Exempel

I följande exempel visas hur du anger ProcessorAffinity egenskapen för en instans av Anteckningar till den första processorn.

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

Kommentarer

Processortillhörigheten för en tråd är den uppsättning processorer som den har en relation till. Med andra ord kan de som den kan schemaläggas att köras på.

ProcessorAffinity representerar varje processor som en bit. Bit 0 representerar processor ett, bit 1 representerar processor två och så vidare. I följande tabell visas en delmängd av möjligheten ProcessorAffinity för ett system med fyra processorer.

Egenskapsvärde (i hexadecimalt) Giltiga processorer
0x0001 1
0x0002 2
0x0003 1 eller 2
0x0004 3
0x0005 1 eller 3
0x0007 1, 2 eller 3
0x000F 1, 2, 3 eller 4

Du kan också ange den enda, föredragna processorn för en tråd genom att ange IdealProcessor egenskapen . En processtråd kan migrera från processor till processor och varje migrering läser in processorcachen igen. Att ange en processor för en tråd kan förbättra prestanda under tunga systembelastningar genom att minska antalet gånger processorcachen läses in igen.

Gäller för

Se även