ProcessThread.IdealProcessor Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Legt den bevorzugten Prozessor für diesen Thread fest, auf dem ausgeführt werden soll.
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
Eigenschaftswert
Der bevorzugte Prozessor für den Thread, der verwendet wird, wenn das System Threads plant, um zu bestimmen, auf welchem Prozessor der Thread ausgeführt werden soll.
- Attribute
Ausnahmen
Das System konnte den Thread nicht so festlegen, dass er auf dem angegebenen Prozessor gestartet wird.
Der Prozess befindet sich auf einem Remotecomputer.
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die IdealProcessor Eigenschaft für eine Instanz von Editor auf den ersten Prozessor festgelegt wird.
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
Hinweise
Der IdealProcessor Wert ist nullbasiert. Wenn Sie also die Threadaffinität für den ersten Prozessor festlegen möchten, legen Sie die Eigenschaft auf Null fest.
Das System plant Threads auf den bevorzugten Prozessoren, wenn möglich.
Ein Prozessthread kann von Prozessor zu Prozessor migrieren, wobei jede Migration den Prozessorcache neu lädt. Die Angabe eines Prozessors für einen Thread kann die Leistung bei hohen Systemlasten verbessern, indem die Anzahl der neu geladenen Prozessorcaches reduziert wird.