Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
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

News Tips .NET Software VCL Software Partners  

Set/get total thread priority
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


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com

Blogspot  greatis.blogspot.com

Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software