ProcessThread.IdealProcessor 屬性

定義

設定執行這個執行緒的慣用處理器。

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

屬性值

執行緒的慣用處理器,用於系統排程執行緒時,以判斷執行執行緒所在的處理器。

屬性

例外狀況

系統無法設定在指定的處理器上啟動執行緒。

處理序位於遠端電腦上。

範例

下列範例示範如何將記事本實例的 屬性設定 IdealProcessor 為第一個處理器。

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

備註

此值 IdealProcessor 是以零起始。 換句話說,若要設定第一個處理器的線程親和性,請將 屬性設定為零。

系統會盡可能在其慣用處理器上排程線程。

進程線程可以從處理器移轉至處理器,每個移轉都會重載處理器快取。 指定線程的處理器可以藉由減少處理器快取重載的次數,來改善大量系統負載下的效能。

適用於