Export (0) Print
Expand All

ProcessThread.IdealProcessor Property

Sets the preferred processor for this thread to run on.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

[BrowsableAttribute(false)]
public int IdealProcessor { set; }

Property Value

Type: System.Int32
The preferred processor for the thread, used when the system schedules threads, to determine which processor to run the thread on.

ExceptionCondition
Win32Exception

The system could not set the thread to start on the specified processor.

PlatformNotSupportedException

The platform is Windows 98 or Windows Millennium Edition.

NotSupportedException

The process is on a remote computer.

The IdealProcessor value is zero-based. In other words, to set the thread affinity for the first processor, set the property to zero.

The system schedules threads on their preferred processors whenever possible.

A process thread can migrate from processor to processor, with each migration reloading the processor cache. Specifying a processor for a thread can improve performance under heavy system loads by reducing the number of times the processor cache is reloaded.

The following example demonstrates how to set the IdealProcessor property for an instance of Notepad to the first processor.

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;
        }
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft