進程的優先級別
Win32支持4种不同的優先級類:
Idle,Normal,High,Realtime
要動態的獲取或設置一個進程的優先級類,可以分別調用
GetPriorityClass()函數和SetPriorityClass()函數
function GetPriorityClass(hProcess:THandle):DWORD;stdcall;
function SetPriorityClass(hProcess:THandle;dwPriorityClass:DWORD):BOOL;stdcall;
hProcess參數用於指定一個進程的句柄,可以配合GetCurrentProcess()函數使用
如要把一個進程的優先級類設為High,可以
if not SetPriorityClass(GetCurrent,HIGH_PRIORITY_CLASS) then
showmessage('Error setting priority class.');
備註
GetCurrentProcess()函數是一個返回當前進程的句柄(Win32 API中有關進程的函數)
相對優先級
一個綫程的相對優先級可以有7种:
Idle,Lowest,Below Normal,normal,above normal,highest和Time Critical
TThread中聲明了一個枚舉類型叫TThreadPriority
type
TThreadPriority=(Idle,Lowest,Below Normal,normal,above normal,highest和Time Critical);
通過TThread的Priority特性,可以獲取或設置一個綫程的相對優先級
MyThread.Priority := tpHightest
本文介绍如何使用Win32 API函数GetPriorityClass和SetPriorityClass来获取和设置Windows进程中线程的优先级。提供了不同优先级类别的定义及通过TThread.Priority属性设置线程相对优先级的方法。
828

被折叠的 条评论
为什么被折叠?



