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

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -