Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - special offer!

Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

WinAPI Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
cdtrrracks.com new!

Blogspot  greatis.blogspot.com

Set/get total thread priority - Application - Tips & Tricks - Greatis Delphi Pages

Total thread priority is a sum of local thread priority and class priority of current process.

Use SetPriorityClass function and Priority property of TThread type to set priority parameters. Use GetPriorityClass function and Priority property of TThread type to get information about total thread priority.


type
  TTestThread = class(TThread)
  private
    j: Integer;
    { Private declarations }
  protected
    procedure GetInfo;
    procedure Execute; override;  
  end;

...

// Set priority
procedure TForm1.Button1Click(Sender: TObject);
var
  NewThread: TTestThread;
begin
  NewThread:=TTestThread.Create(False);
  case RadioGroup2.ItemIndex of
    0: NewThread.Priority:=tpIdle;
    1: NewThread.Priority:=tpLowest;
    2: NewThread.Priority:=tpNormal;
    3: NewThread.Priority:=tpHighest;
    4: NewThread.Priority:=tpTimeCritical;
  end;
  case Form1.RadioGroup1.ItemIndex of
    0: SetPriorityClass(GetCurrentProcess, IDLE_PRIORITY_CLASS);
    1: SetPriorityClass(GetCurrentProcess, NORMAL_PRIORITY_CLASS);
    2: SetPriorityClass(GetCurrentProcess, HIGH_PRIORITY_CLASS);
    3: SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  end;
end;

// Get priority
procedure TTestThread.GetPriority;
var
  TotalStr: string;
begin
  TotalStr:='Total Priority = ';
  case Priority of
    tpIdle: TotalStr:=TotalStr+'Idle';
    tpLowest: TotalStr:=TotalStr+'Lowest';
    tpNormal: TotalStr:=TotalStr+'Normal';
    tpHighest: TotalStr:=TotalStr+'Highest';
    tpTimeCritical: TotalStr:=TotalStr+'Time critical';
  end;
  TotalStr:=TotalStr+' (local thread) + ';

  case GetPriorityClass(GetCurrentProcess) of
    IDLE_PRIORITY_CLASS: TotalStr:=TotalStr+'Idle';
    NORMAL_PRIORITY_CLASS: TotalStr:=TotalStr+'Normal';
    HIGH_PRIORITY_CLASS: TotalStr:=TotalStr+'High';
    REALTIME_PRIORITY_CLASS: TotalStr:=TotalStr+'Realtime';
  end;
  TotalStr:=TotalStr+' (class priority)';

  Form1.Label1.Caption:=TotalStr;
end;
Related topics
Synchronize thread with application
Create/destroy thread
Suspend/resume thread

For more
Delphi Help

Download source