How can i limit cpu usage of windows processes using C# -


i need write class attach windows processes, monitor , limit cpu usage. process priority changing not me @ need write program similar bes or threadmaster. need make class that's doing (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 made clear want accomplish, have no idea how. every appreciated.

  • you create job object
  • you limit cpu job
  • you attach target process job

see job objects, createjobobject, setinformationjobobject , jobobject_cpu_rate_control_information, assignprocesstojobobject. not attempt hand-craft own in-house process throttling, let component designed task (ie. jobs) handle task.

see working example of createjobobject/setinformationjobobject pinvoke in .net? managed usage of nt job native api.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

Error while updating a record in APEX screen -

c++ - In an add-in in Excel, written in C(++), how does one get the name of the function which called into the addin? -