delphi 優先級和時序安排

来源:互联网 发布:allshare软件 编辑:程序博客网 时间:2024/05/09 09:47

進程的優先級別
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 

原创粉丝点击