Merci de ta réponse,
Commen fais-je pour reconnaitre dans la liste des thread du process, celui qui correspond au thread sur lequel je veux affecter SetThreadAffinityMask. Car ce n'est pas sur mon processus à moi que veux appliquer cette propierté mais sur un autre.
Voici le code qui me sert d'exemple :
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
namespace Tester
{
class Program
{
[DllImport("kernel32")]
static extern int GetCurrentThreadId();
static void Main()
{
Thread t = new Thread(
new ThreadStart(DoWork));
t.Start();
t.Join();
}
static void DoWork()
{
foreach(ProcessThread pt in Process.GetCurrentProcess().Threads)
{
// Voilà c'est ici : Pour trouver le utid du threadcourrant OK, mais comment faire si il s'agit d'un autre thread. Dans mon cas, il s'agit d'un trhread qui fait le QueryPerformanceCounter (voir plus bas) ?
int utid = GetCurrentThreadId();
if (utid == pt.Id)
{
pt.ProcessorAffinity = (IntPtr)(1); // Set affinity for this
thread to CPU #1
Console.WriteLine("Set");
}
}
}
}
}
// Ici mon thread sur leque je voudrais applique l'ProcessorAffinity
publiclong Stop(){
QueryPerformanceCounter(
out stopTime);return(stopTime);}
Merci encore.