Hello,
I am writing my program for windows and I am wondering how I can make my program run below low priority. If you know the code to set do this please let me know.
thanks.
Printable View
Hello,
I am writing my program for windows and I am wondering how I can make my program run below low priority. If you know the code to set do this please let me know.
thanks.
Wrong section, should be in Windows programming... But:
http://msdn2.microsoft.com/en-us/library/ms686219.aspx
Hello,
I've tried that link above but I can't get it to work. I don't think I am doing it right. How do I implment it in C/C++
thanks.
Maybe post your attempt, and try to come up with something better than "doesn't work".
getdisk.cpp:32: error: `PROCESS_MODE_BACKGROUND_BEGIN' undeclared (first use
this function)
getdisk.cpp:32: error: (Each undeclared identifier is reported only once for
each function it appears in.)
getdisk.cpp:35: error: `ERROR_PROCESS_MODE_ALREADY_BACKGROUND' undeclared
(first use this function)
getdisk.cpp:38: error: label `Cleanup' used but not defined
getdisk.o - 4 error(s), 0 warning(s)
Code:#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main(){
DWORD dwError, dwPriClass;
if(!SetPriorityClass(GetCurrentProcess(), PROCESS_MODE_BACKGROUND_BEGIN))
{
dwError = GetLastError();
if( ERROR_PROCESS_MODE_ALREADY_BACKGROUND == dwError)
printf("Already in background mode\n");
else printf("Failed to enter background mode (%d)\n", dwError);
goto Cleanup;
}
// Display priority class
dwPriClass = GetPriorityClass(GetCurrentProcess());
printf("Current priority class is 0x%x\n", dwPriClass);
return 0;
}
Background processing is only available on Vista. Even if you have Vista, it will probably require an update to your header and library files. You could use BELOW_NORMAL_PRIORITY_CLASS or IDLE_PRIORITY_CLASS instead.
I'm searching google for BELOW_NORMAL_PRIORITY_CLASS but haven't found any good documentation. can you recommend a source?
or let me know the small snip of code that will set my program to run in below low priority.
thanks.
should do it.Code:SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);
to read more about process and thread priorities - you can look at this: http://msdn2.microsoft.com/en-us/library/ms685100.aspx
dwPriorityClass is one of the following:Code:BOOL SetPriorityClass(
HANDLE hProcess, // handle to process
DWORD dwPriorityClass // priority class
);
REALTIME_PRIORITY_CLASS
HIGH_PRIORITY_CLASS
ABOVE_NORMAL_PRIORITY_CLASS
NORMAL_PRIORITY_CLASS
BELOW_NORMAL_PRIORITY_CLASS
IDLE_PRIORITY_CLASS
be very careful with REALTIME_PRIORITY_CLASS . if your program uses a lot of cpu cycles it can hog your entire processor, preventing windows from responding even to the 3 finger salute.
Windows Task Manager, by default, is at high priority. If using high priority, I suggest putting Windows Task Manager to "Realtime" priority to make it easier to close (right-click on the process (taskmgr.exe) and choose set priority > Realtime to do so). If you encounter an infinite loop without doing this and realtime is set for your program and WTM is only high, you're doomed. I just thought I'd point this potential "hazard" out.