【发布时间】:2012-05-09 21:37:53
【问题描述】:
我需要启动 IE 并将关联设置到特定的单个 CPU。 运行以下 c# 代码时,正如预期的那样,notepad.exe 已启动并且其关联设置为仅 cpu2,奇怪的是 iexplore.exe 启动时其关联设置为仅 cpu0。无论我将 ProcessorAffinity 设置为什么,iexplore.exe 总是转到 cpu0。
我已经在 4 核 xp 32 位和 4 核 2008 64 位 IE8 上进行了测试。
using System;
using System.Diagnostics;
public class Launch
{
public static void Main(string[] args)
{
lauchWithAffinity("c:/windows/system32/notepad.exe");
lauchWithAffinity("c:/Program Files/Internet Explorer/IEXPLORE.EXE");
}
static void lauchWithAffinity(string exePath)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = exePath;
Process myProcess =Process.Start(start);
myProcess.ProcessorAffinity = (System.IntPtr)4; //3rd cpu aka cpu2
//http://msdn.microsoft.com/en-us/library/system.diagnostics.process.processoraffinity.aspx
}
}
【问题讨论】:
-
我放了一个 MessageBox.Show(myProcess.ProcessorAffinity.ToString());将 Affinity 从 15 设置为 4 后,msgbox 会打印 4,您期望什么不起作用?
-
您是否尝试在
launchWithAffinity方法周围放置一个try catch以查看是否抛出异常?
标签: c# multithreading internet-explorer