Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何限制进程使用的核心数?_C#_Process_Cpu Cores - Fatal编程技术网

C# 如何限制进程使用的核心数?

C# 如何限制进程使用的核心数?,c#,process,cpu-cores,C#,Process,Cpu Cores,我想让我的程序打开一些其他进程,项目的一个要求是,每个打开的进程只能在单个核心上运行 我知道可以使用processorAffinity选择特定的处理器,但是否可以设置最大内核数(在我的案例1中)?您必须尝试使用 可能是重复的,我很想见到写这个要求的人,这样我就可以问他/她这到底是为了什么。@Gusdor一些旧的应用程序在多核上运行时会崩溃。这就是我来这里的原因。 using System; using System.Diagnostics; namespace ProcessThreadIde

我想让我的程序打开一些其他进程,项目的一个要求是,每个打开的进程只能在单个核心上运行

我知道可以使用processorAffinity选择特定的处理器,但是否可以设置最大内核数(在我的案例1中)?

您必须尝试使用


可能是重复的,我很想见到写这个要求的人,这样我就可以问他/她这到底是为了什么。@Gusdor一些旧的应用程序在多核上运行时会崩溃。这就是我来这里的原因。
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;
        }
    }
}