Aracılığıyla paylaş


ProcessThread.ProcessorAffinity Özellik

Tanım

İlişkili iş parçacığının üzerinde çalışabileceği işlemcileri ayarlar.

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

Özellik Değeri

IntPtr

nativeint

Her IntPtr biri iş parçacığının üzerinde çalışabileceği bir işlemciyi temsil eden bir bit kümesine işaret eden bir.

Öznitelikler

Özel durumlar

İşlemci benzitesi ayarlanamadı.

İşlem uzak bir bilgisayarda gerçekleştirilir.

Örnekler

Aşağıdaki örnekte, Not Defteri örneğinin özelliğinin ProcessorAffinity ilk işlemciye nasıl ayarlanacağı gösterilmektedir.

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

Açıklamalar

bir iş parçacığının işlemci benzitesi, ilişkisi olan işlemci kümesidir. Başka bir deyişle, bunlar üzerinde çalışmak üzere zamanlanabilir.

ProcessorAffinity her işlemciyi bit olarak temsil eder. Bit 0 işlemci 1'i, bit 1 ise işlemci ikiyi temsil eder ve bu şekilde devam eder. Aşağıdaki tabloda, dört işlemcili sistem için mümkün ProcessorAffinity olan bir alt küme gösterilmektedir.

Özellik değeri (onaltılık) Geçerli işlemciler
0x0001 1
0x0002 2
0x0003 1 veya 2
0x0004 3
0x0005 1 veya 3
0x0007 1, 2 veya 3
0x000F 1, 2, 3 veya 4

Özelliğini ayarlayarak bir iş parçacığı için tercih edilen tek işlemciyi IdealProcessor de belirtebilirsiniz. bir işlem iş parçacığı işlemciden işlemciye geçiş yapabilir ve her geçiş işlemci önbelleğini yeniden yükler. İş parçacığı için bir işlemci belirtmek, işlemci önbelleğinin yeniden yüklenme sayısını azaltarak ağır sistem yükleri altında performansı artırabilir.

Şunlara uygulanır

Ayrıca bkz.