I need to write a class that will attach to certain windows processes, monitor and limit their cpu usage. Process priority changing would not help me at all so i really need to write a program that is basically similar to BES or ThreadMaster. So i need to make a class that's doing something like this (pseudo code):
public void cpuLimiter(pid)
{
ProcessHandle handle = attachToProcess(pid);
while (cpuLimiting)
{
if (handle.cpuUsage > 30%)
{
handle.sleep(100miliseconds);
}
sleep(10miliseconds);
}
closeHandle(pid);
}
I hope i made it clear what i want to accomplish, just i have no idea how. Every help is appreciated.