Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
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
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.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