SetThreadPriority sets the priority of the specified Thread
[Cpp]
BOOL SetThreadPriority (HANDLE hThread, // handle to the thread
Int nPriority // thread priority level );
Parameter description
Thread handle to be set for hThread
The nPriority priority parameter can be set as the following parameter.
THREAD_PRIORITY_ABOVE_NORMAL has a higher priority than General
THREAD_PRIORITY_BELOW_NORMAL is generally lower
THREAD_PRIORITY_HIGHEST is two levels higher than general (highest)
THREAD_PRIORITY_IDLE idle
THREAD_PRIORITY_LOWEST is 2 lower (lowest)
THREAD_PRIORITY_NORMAL general level
THREAD_PRIORITY_TIME_CRITICAL Real-Time
[Cpp]
# Include <Windows. h>
# Include <iostream>
Using namespace std;
Dword winapi ThreadNormal (LPVOID lpParam)
{
Int I = 0;
While (I ++ <10)
Cout <"Normal Thread is running" <endl;
Return 0;
}
Dword winapi ThreadAboveNormal (LPVOID lpParam)
{
Int I = 0;
While (I ++ <10)
Cout <"Above Normal Thread is running" <endl;
Return 0;
}
Int main ()
{
DWORD dwThreadID;
HANDLE hThread [2];
// Create a abve Normal Thread
HThread [0] = CreateThread (NULL, 0, ThreadAboveNormal, NULL, create_suincluded, & dwThreadID );
// Set priority is abve normal www.2cto.com
SetThreadPriority (hThread [0], THREAD_PRIORITY_ABOVE_NORMAL );
// Resume thread
ResumeThread (hThread [0]);
// Create a Normal Thread
HThread [1] = CreateThread (NULL, 0, ThreadNormal, NULL, 0, & dwThreadID );
// Wait two
WaitForMultipleObjects (2, hThread, TRUE, INFINITE );
// Close thread
CloseHandle (hThread [0]);
CloseHandle (hThread [1]);
Return 0;
}