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

プロパティを設定することで、スレッドの 1 つの優先プロセッサを IdealProcessor 指定することもできます。 プロセス スレッドはプロセッサからプロセッサに移行でき、各移行ではプロセッサ キャッシュが再読み込みされます。 スレッドにプロセッサを指定すると、プロセッサ キャッシュが再読み込みされる回数を減らすことで、システムの負荷が高い場合のパフォーマンスを向上させることができます。

適用対象

こちらもご覧ください