Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set priority of a loop to High??

0 views
Skip to first unread message

Eli

unread,
Nov 8, 2001, 8:35:09 PM11/8/01
to
Hi,
I have a simple loop like:

for i:=1 to 7500 do; // do nothing

I measure this time,
but I have to give it the highest priority so other tasks will not interrupt
it.
How do I do it?

the idea should me as follow:

- GIVE THE NEXT LOOP THE HIGHEST PRIORITY
- DO THE LOOP
- DISABLE THE HIGHEST PRIORITY TO THE LOOP

Thanks in advance!

Eli

Scott

unread,
Nov 8, 2001, 10:57:39 AM11/8/01
to
Hello,

As far as i can remember this can be achieved as follows...

SetPriorityClass(Form1.Handle,HIGH_PRIORITY_CLASS);

--or---

SetPriorityClass(Form1.Handle,REALTIME_PRIORITY_CLASS );

The last one sets the priority to the highest available to windows, but also
means that all processes will sease thus causing a lot of processing when
the loop has finished.

As far as i know there is not function in the windows api for canceling a
priority level so you would simply call the function again as follows

SetPriorityClass(Form1.Handle,NORMAL_PRIORITY_CLASS );

"Eli" <el...@roseman.co.il> wrote in message news:3beaa644_1@dnews...

Wayne

unread,
Nov 8, 2001, 5:21:28 PM11/8/01
to
Another approach could be:

Move the loop to a thread and disable input to your main application (say
show a form modally that says processing) till the thread is finished.
TThread has a Priority Property. This would allow you to give the thread a
high priority to do the processing and allow you to give the user a way to
cancel (Say a cancel button on the processing form).

Hope this helps.

Thanks
Wayne


"Scott" <Sc...@Input.ie> wrote in message news:3beaab29$1_2@dnews...

Bruno Lovatti

unread,
Nov 9, 2001, 11:02:52 AM11/9/01
to
var
PriorityClass, Priority: Integer;

begin
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

your loop

SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);
end;


Bruno Lovatti
Hortifruti - Tecnologia da Informação


0 new messages