Click here to Skip to main content
15,920,030 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Passing variables between dialogs Pin
Rick York19-Jul-05 18:09
mveRick York19-Jul-05 18:09 
Questionsystem() ? Pin
kevingpo19-Jul-05 7:39
kevingpo19-Jul-05 7:39 
AnswerRe: system() ? Pin
David Crow19-Jul-05 7:42
David Crow19-Jul-05 7:42 
AnswerRe: system() ? Pin
toxcct19-Jul-05 22:54
toxcct19-Jul-05 22:54 
Generallimiting cpu usage for a process Pin
mbulhoes19-Jul-05 6:42
mbulhoes19-Jul-05 6:42 
GeneralRe: limitting cpu usage for a process Pin
Graham Bradshaw19-Jul-05 12:34
Graham Bradshaw19-Jul-05 12:34 
GeneralRe: limitting cpu usage for a process Pin
sfeldi19-Jul-05 22:16
sfeldi19-Jul-05 22:16 
GeneralRe: limiting cpu usage for a process Pin
mbulhoes20-Jul-05 8:06
mbulhoes20-Jul-05 8:06 
Thanks Graham. I thought I had gone the suspend/resume route last week, but I tried so many things, it's all kind of fuzzy right now.

I tried it again this morning, and it seems that if you 1) set the priority class to IDLE_PRIORITY_CLASS, and 2) do the suspend/resume dance every second, you can achieve the desired cpu usage percentage cap.

Example:

CreateProcess(args...) // priority= CREATE_SUSPENDED
SetPriorityClass(procInfo.hProcess, IDLE_PRIORITY_CLASS);

int cap = 60; // cap at 60% usage
int run = cap * 10; // run for 600 ms
int idle = (100 - cap) * 10; // suspend for 400 ms

bool isdone = false;
while (! isdone) {
ResumeThread(procInfo.hThread);

// need better handling to determine when process is complete
isdone = ::WaitForSingleObject(procInfo.hProcess, run) != WAIT_TIMEOUT;

if (! isdone) {
SuspendThread(procInfo.hThread);
isdone = ::WaitForSingleObject(procInfo.hProcess, idle) != WAIT_TIMEOUT;
}
}

The above code snippet seems to work fine without any adverse effects on the running process.

Thanks to all who replied.
mb
QuestionHow to retrive users info from a Windows Server Pin
ivax19-Jul-05 5:43
ivax19-Jul-05 5:43 
AnswerRe: How to retrive users info from a Windows Server Pin
David Crow19-Jul-05 6:05
David Crow19-Jul-05 6:05 
GeneralRe: How to retrive users info from a Windows Server Pin
ivax19-Jul-05 6:13
ivax19-Jul-05 6:13 
GeneralRe: How to retrive users info from a Windows Server Pin
David Crow19-Jul-05 9:33
David Crow19-Jul-05 9:33 
GeneralRe: How to retrive users info from a Windows Server Pin
Graham Bradshaw19-Jul-05 12:37
Graham Bradshaw19-Jul-05 12:37 
GeneralNeed help with Worker Thread Code Pin
Freddie Code19-Jul-05 5:16
Freddie Code19-Jul-05 5:16 
GeneralRe: Need help with Worker Tread Code Pin
David Crow19-Jul-05 5:17
David Crow19-Jul-05 5:17 
GeneralRe: Need help with Worker Thread Code Pin
khan++19-Jul-05 20:49
khan++19-Jul-05 20:49 
QuestionWhy does creating a static window from a console app cause havok? Pin
IGx8919-Jul-05 5:10
IGx8919-Jul-05 5:10 
AnswerRe: Why does creating a static window from a console app cause havok? Pin
David Crow19-Jul-05 5:16
David Crow19-Jul-05 5:16 
GeneralRe: Why does creating a static window from a console app cause havok? Pin
IGx8919-Jul-05 5:50
IGx8919-Jul-05 5:50 
GeneralRe: Why does creating a static window from a console app cause havok? Pin
David Crow19-Jul-05 6:10
David Crow19-Jul-05 6:10 
GeneralRe: Why does creating a static window from a console app cause havok? Pin
IGx8919-Jul-05 7:03
IGx8919-Jul-05 7:03 
GeneralRe: Why does creating a static window from a console app cause havok? Pin
David Crow19-Jul-05 7:32
David Crow19-Jul-05 7:32 
GeneralRe: Why does creating a static window from a console app cause havok? Pin
Trollslayer19-Jul-05 6:11
mentorTrollslayer19-Jul-05 6:11 
GeneralRe: Why does creating a static window from a console app cause havok? Pin
IGx8919-Jul-05 7:05
IGx8919-Jul-05 7:05 
GeneralRe: Why does creating a static window from a console app cause havok? Pin
Trollslayer19-Jul-05 7:35
mentorTrollslayer19-Jul-05 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.