ProcessThread.IdealProcessor Właściwość

Definicja

Ustawia preferowany procesor dla tego wątku do uruchomienia.

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

Wartość właściwości

Preferowany procesor wątku, używany, gdy system planuje wątki, aby określić procesor do uruchomienia wątku.

Atrybuty

Wyjątki

System nie może ustawić wątku do uruchomienia na określonym procesorze.

Proces jest na komputerze zdalnym.

Przykłady

W poniższym przykładzie pokazano, jak ustawić IdealProcessor 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

Wartość IdealProcessor jest oparta na zerowej wartości. Innymi słowy, aby ustawić koligację wątku dla pierwszego procesora, ustaw właściwość na zero.

System planuje wątki na preferowanych procesorach, gdy jest to możliwe.

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ść pod dużym obciążeniem systemu przez zmniejszenie liczby ponownych ładowania pamięci podręcznej procesora.

Dotyczy