ProcessThread.ProcessorAffinity 속성

정의

관련 스레드가 실행될 수 있는 프로세서를 설정합니다.

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

속성 값

IntPtr

nativeint

비트 집합을 가리키는 IntPtr입니다. 각각의 비트는 스레드가 실행될 수 있는 프로세서를 나타냅니다.

특성

예외

프로세서 선호도를 설정할 수 없는 경우

프로세스가 원격 컴퓨터에 있는 경우

예제

다음 예제에서는 메모장 인스턴스의 ProcessorAffinity 속성을 첫 번째 프로세서로 설정하는 방법을 보여줍니다.

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

설명

스레드의 프로세서 선호도는 관계가 있는 프로세서 집합입니다. 즉, 실행되도록 예약할 수 있습니다.

ProcessorAffinity 는 각 프로세서를 비트로 나타냅니다. 비트 0은 프로세서 1을 나타내고 비트 1은 프로세서 2를 나타냅니다. 다음 표에서는 4 프로세서 시스템에 대해 가능한 ProcessorAffinity 의 하위 집합을 보여 줍니다.

속성 값(16진수) 유효한 프로세서
0x0001 1
0x0002 2
0x0003 1 또는 2
0x0004 3
0x0005 1 또는 3
0x0007 1, 2 또는 3
0x000F 1, 2, 3 또는 4

속성을 설정 IdealProcessor 하여 스레드에 대해 기본 설정된 단일 프로세서를 지정할 수도 있습니다. 프로세스 스레드는 프로세서 캐시를 다시 로드할 때마다 프로세서에서 프로세서로 마이그레이션할 수 있습니다. 스레드에 프로세서를 지정하면 프로세서 캐시가 다시 로드되는 횟수를 줄여 시스템 부하가 많은 상태에서 성능을 향상시킬 수 있습니다.

적용 대상

추가 정보