if(!(SetPriorityClass(Handle1, IDLE_PRIORITY_CLASS)))
MessageBox(0, "Could not lower the priority class for thread 1", "Test", 0);
DWORD error = GetLastError();
Error code problems when changing thread priority class.
I have this code in my app to change the priority class of a worker thread which I create.
The SetPriorityClass is failing, i.e. returning 0, however when I check the error code with GetLastError() it gives me a 0, which apparently means that operation completed successfully?
Am I missing something obvious?
Kind regards, Mark Coleman.
try:
edit: darn.. beaten to it :P
DWORD error;if(!(SetPriorityClass(Handle1, IDLE_PRIORITY_CLASS))){ error = GetLastError(); MessageBox(0, "Could not lower the priority class for thread 1", "Test", 0);}
edit: darn.. beaten to it :P
Turns out the handle is created fine so it must be something to do with this...
From MSDN:
BOOL SetPriorityClass(
HANDLE hProcess,
DWORD dwPriorityClass
);
Parameters
hProcess
[in] Handle to the process.
****The handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Security and Access Rights.**** <--- THIS
dwPriorityClass
[in] Priority class for the process. This parameter can be one of the following values.
But I can't for the life of me figure out how to set this access right...
Doe's anybody have any idea? The MSDN documentation seems to be circular on the subject.
Mark Coleman
From MSDN:
BOOL SetPriorityClass(
HANDLE hProcess,
DWORD dwPriorityClass
);
Parameters
hProcess
[in] Handle to the process.
****The handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Security and Access Rights.**** <--- THIS
dwPriorityClass
[in] Priority class for the process. This parameter can be one of the following values.
But I can't for the life of me figure out how to set this access right...
Doe's anybody have any idea? The MSDN documentation seems to be circular on the subject.
Mark Coleman
SetPriorityClass(GetCurrentProcess(),IDLE_PRIORITY_CLASS);
Should work, i think Process Security and Access Rights has something to do with the logged on user, could be totally wrong though.
Should work, i think Process Security and Access Rights has something to do with the logged on user, could be totally wrong though.
Quote:Original post by mrmrcoleman
I have this code in my app to change the priority class of a worker thread which I create.
Just to be sure: Aren't you using the wrong function?
The SetPriorityClass function sets the priority class for the specified process.
The SetThreadPriority function sets the priority value for the specified thread.
If you set the current process to idle I think you may get into trouble.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement