Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-08 Thread Lukasz Sokol
On 05/12/14 13:53, Michael Schnell wrote:
> On 12/04/2014 04:24 PM, Lukasz Sokol wrote:
>> Or e.g. I run FindFirst/FindNext loop over a large number of files,
>> or even if I delegate reading of a file to another procedure, still
>> takes time while nothing else can happen... (although /that/
>> actually I can imagine doing in a thread). Then such
>> Application.ProcessMessages is about the only option ?
> 
> A long winding loop (such as "FindNext" freezes the GUI and all
> TTimers if you don't include ProcessMessages.

Yes. 

> 
> If doing the loop in a Thread you can send status messages to the
> main (GUI) thread by means of TThread.Queue or
> Application.QueueAsyncCall. (You do know that you can't access the
> GUI from a worker thread.)
> 

Yes. 

These are 'technicalities' of inter-thread communications 
more specifically thread-to-mainthread communication)
that can be figured out relatively easily and found when you need them.

Let's assume we have a procedure that is executed once per the window 
being created (or shown) : first we read a file list into a list of
file names, read some attributes (e.g. file date) into a string list
and put it into a TMemo or some TFileList; then we read a file list with a 
slightly different
mask and read their names/dates and put it into another TMemo or TFileList;
and finally, we read yet another set of files and put names/dates  into a memo 
or filelist.

(as it would be, say a result of having input files created by external 
program, fed to another external program,
and another external processing program called on the output of the second one, 
so we have 3 sets of files:
input, itermediate, output.)

Let's also assume that the files need to be read in particular order
(as what we want to read in second and third indexing may depend on
 what we read in the first and second one).

So we create TThread workers for indexing1, indexing2 and indexing3,
they return TStringList's to us, we call some string-list processing procedures
on their results [which don't take as much time to process so they are
called in main thread context with ProcessMessages in their loops, but if they
were to be more 'complex' and time-consuming, they would be put into threads of 
themselves too]
and give certain parameters to the next indexing' (or worker) thread to work 
with.

What I mean is, when I have a long-winding [long-timed] sequence of worker 
threads like this,
written inside of an 'OnShow' or 'OnClick', I want to have the whole of
the sequence written in ONE logical flow, inside one procedure code block...
right ? (and say it's written so that one procedure is not longer than 3 
screens vertically ;)
 and has no more than 3 levels of nesting too;) and most importantly
to use same local variables (locally created string lists, for example).

(ok I know this probably is an 'obvious' thing for any formally trained 
programmer
of just about any language out there... ;) but I ain't one... )

The advice to OP was, fire up a thread (or TTimer) for such long processing 
loops 
as the 'last thing' in the sequence, then continue the flow of whatever you 
need to do
in another procedure, called after the thread/ttimer is done...

which I argue is not optimal /to humans/ as a) it disturbs reading order and b) 
disallows
the portions of the logically close code from using same local variables
and c) if put as subroutines, disturbs reading flow even worse.


> -Michael
> 

el es


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-08 Thread Michael Schnell

On 12/08/2014 10:20 AM, Mattias Gaertner wrote:

BTW, TThread.Synchronize is hardly a queue.

Yes there is a Queue (internally in the RTL it's called "*ThreadQueue*" )

This is the source code in the RTL:




class procedure TThread.Synchronize(AThread: TThread; AMethod: 
TThreadMethod);

  begin
{ ensure that we have a TThread instance }
if not Assigned(AThread) then
  AThread := CurrentThread;

{ the Synchronize event is instantiated on demand }
AThread.InitSynchronizeEvent;

AThread.FSynchronizeEntry^.Exception := Nil;
AThread.FSynchronizeEntry^.Method := AMethod;
*ThreadQueueAppend*(AThread.FSynchronizeEntry);

AThread.FSynchronizeEntry^.Method := Nil;
AThread.FSynchronizeEntry^.Next := Nil;
  end;


-Michael
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-08 Thread Mattias Gaertner
On Mon, 08 Dec 2014 10:03:15 +0100
Michael Schnell  wrote:

> On 12/07/2014 10:05 PM, Mattias Gaertner wrote:
> > HandleMessage waits until a message is in the queue, calls 
> > ProcessMessages and returns.
> 
> Does it wait up as well when some Event is pushed upon the GUI queue (in 
> Windows a Windows message occurs, in Linux a Lazarus Event), as when an 
> Event happens for the TThread "Synchonize"  Event Queue in the fpc RTL ?

Yes. 
And as I corrected myself: It first processes messages and then
waits.
BTW, TThread.Synchronize is hardly a queue.

 
Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-08 Thread Michael Schnell

On 12/08/2014 10:03 AM, Michael Schnell wrote:


Does it wait up

Sorry Typo: "wake up"

-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-08 Thread Michael Schnell

On 12/07/2014 10:05 PM, Mattias Gaertner wrote:
HandleMessage waits until a message is in the queue, calls 
ProcessMessages and returns.


Does it wait up as well when some Event is pushed upon the GUI queue (in 
Windows a Windows message occurs, in Linux a Lazarus Event), as when an 
Event happens for the TThread "Synchonize"  Event Queue in the fpc RTL ?


-Michael ( I am going to upgrade my Event handling test program for 
tests with HandleMessage ASAP).


-Michael


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-07 Thread Mattias Gaertner
On Sun, 7 Dec 2014 22:05:29 +0100
Mattias Gaertner  wrote:

> On Sun, 7 Dec 2014 16:50:10 -0300
> Flávio Etrusco  wrote:
> 
> >[...]
> > > Also implemented in Lazarus.
> > > HandleMessage waits till the next message.
> > 
> > Unfortunately in Lazarus it doesn't (wait).
> 
> If it would not wait you would see 100% load in LCL
> applications.
> HandleMessage waits until a message is in the queue, calls
> ProcessMessages and returns.

Sorry. I was wrong.

It first calls ProcessMessages and then waits for next message.

Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-07 Thread Mattias Gaertner
On Sun, 7 Dec 2014 16:50:10 -0300
Flávio Etrusco  wrote:

>[...]
> > Also implemented in Lazarus.
> > HandleMessage waits till the next message.
> 
> Unfortunately in Lazarus it doesn't (wait).

If it would not wait you would see 100% load in LCL
applications.
HandleMessage waits until a message is in the queue, calls
ProcessMessages and returns.


Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-07 Thread Flávio Etrusco
On Sat, Dec 6, 2014 at 1:15 PM, Mattias Gaertner
 wrote:
> On Sat, 06 Dec 2014 16:02:40 +0100
> JuuS  wrote:
>
>> Hi all,
>>
>> A bit late with this and haven't read everything through and through but...
>>
>> I worked with Delphi for some time and, yes, Application.Processmessages
>> brings system to knees and processor to 100%.
>>
>> But in Delphi there was also an Application.Handlemessage...used like this:
>>
>> repeat
>>   Application.HandleMessage;
>> until AKeyPressed (or whatever);
>>
>> ...and the system is calm (normal load) and the program responsive. It
>> was like Handlemessage was sipping water drops dripping from a fern
>> leaf, while Processmessages was drinking from a fire hose... :)
>>
>> I don't know if anyone else has mentioned this, not reading all the
>> mails, and also don't know if Handlemessage is implemented in Lazarus
>> (not being by my computer right now).
>
> Also implemented in Lazarus.
> HandleMessage waits till the next message.
>
>
> Mattias

Unfortunately in Lazarus it doesn't (wait).

-Flávio

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-06 Thread Mattias Gaertner
On Sat, 06 Dec 2014 16:02:40 +0100
JuuS  wrote:

> Hi all,
> 
> A bit late with this and haven't read everything through and through but...
> 
> I worked with Delphi for some time and, yes, Application.Processmessages
> brings system to knees and processor to 100%.
> 
> But in Delphi there was also an Application.Handlemessage...used like this:
> 
> repeat
>   Application.HandleMessage;
> until AKeyPressed (or whatever);
> 
> ...and the system is calm (normal load) and the program responsive. It
> was like Handlemessage was sipping water drops dripping from a fern
> leaf, while Processmessages was drinking from a fire hose... :)
> 
> I don't know if anyone else has mentioned this, not reading all the
> mails, and also don't know if Handlemessage is implemented in Lazarus
> (not being by my computer right now).

Also implemented in Lazarus.
HandleMessage waits till the next message.


Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-06 Thread JuuS
Hi all,

A bit late with this and haven't read everything through and through but...

I worked with Delphi for some time and, yes, Application.Processmessages
brings system to knees and processor to 100%.

But in Delphi there was also an Application.Handlemessage...used like this:

repeat
  Application.HandleMessage;
until AKeyPressed (or whatever);

...and the system is calm (normal load) and the program responsive. It
was like Handlemessage was sipping water drops dripping from a fern
leaf, while Processmessages was drinking from a fire hose... :)

I don't know if anyone else has mentioned this, not reading all the
mails, and also don't know if Handlemessage is implemented in Lazarus
(not being by my computer right now).

Hope this helps someone.

Julius

On 05/12/2014 14:59, Lukasz Sokol wrote:
> On 04/12/14 20:34, waldo kitty wrote:
>> On 12/4/2014 10:24 AM, Lukasz Sokol wrote:
>>> (OnTimer execution has the same problem : inevitably splits the procedure 
>>> into
>>> more procedures, that can no longer use same local variables and stuff)
>>
>> you can't make them subroutines of the subroutine?
>>
> 
> Interesting, but breaks the flow of human reading (as, comparably, top 
> posting does):
> because subroutines have to be defined at the top of the subroutine...
> 
>> eg:
>>
>> program foobie;
>>
>> procedure dofoobie;
>>
>> var
>>   thisfoo : integer = 0;
>>   thatfoo : integer = 0;
>>
>>   procedure littlefoobie; ///  << this logically comes AFTER but we don't 
>> know that until we read...
>>   begin
>> inc(thisfoo,thatfoo);
>> inc(thatfoo); /// this probably is not much of a problem when a 
>> subroutine is this short
> // it's the much-longer ones 
>>   end;
>>
>> begin
>>   repeat
>> begin
>   foobiee( ... ); /// ... that this logically comes first
>>   littlefoobie;
>>   writeln(thisfoo,'',thatfoo);
>> end;
>>   until thisfoo >= 25;
>> end;
>>
>> begin
>>   dofoobie;
>> end.
>>
>>
> 
> How would you put this into subroutines:
> 
> 
> procedure very_long_initialization_routine;
> // (var some_big_list_of_variables... )
> 
> begin
>   Timer1.Enabled := false;
>  
>   do_this();
>   do_that();  // now for the sake of argument, say this routine fires up a 
> thread reading in 1s of file names through FindFirst/FindNext
>   // now we need a long delay before calling do_foo() that would operate on 
> that list, so
>  
>   Timer1.OnTimer := do_the_rest_of_initialization();
>   Timer1.Delay   := 1; // pseudo-code, can't remember how was that 
> exactly called
>   Timer1.Enabled := true;
>   // that's it, we need to split here to give message loop opportunity to do 
> Application.ProcessMessages
> end;
> 
> /// (and here we break variable locality...)
> 
> procedure do_the_rest_of_initialization;
> begin
>   do_foo(...);
>   // rinse&repeat if you have more sections like that doing different 
> things...
> end;
> 
> One can of course have TTimer as locally created object in the 
> very_long_initialization_routine, yes... but an
> Application.ProcessMessages + sleep(100) loop is probably much easier to type 
> (and debug, and read).
> 
> Not mentioning that probably loop would be a wee little (tiny) bit more 
> precise than calling the Timer ?
> 
> (that of course YMMV and IMvhO)
> 
> el_es
> 
> 
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
> 

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-05 Thread Lukasz Sokol
On 04/12/14 20:34, waldo kitty wrote:
> On 12/4/2014 10:24 AM, Lukasz Sokol wrote:
>> (OnTimer execution has the same problem : inevitably splits the procedure 
>> into
>> more procedures, that can no longer use same local variables and stuff)
> 
> you can't make them subroutines of the subroutine?
> 

Interesting, but breaks the flow of human reading (as, comparably, top posting 
does):
because subroutines have to be defined at the top of the subroutine...

> eg:
> 
> program foobie;
> 
> procedure dofoobie;
> 
> var
>   thisfoo : integer = 0;
>   thatfoo : integer = 0;
> 
>   procedure littlefoobie; ///  << this logically comes AFTER but we don't 
> know that until we read...
>   begin
> inc(thisfoo,thatfoo);
> inc(thatfoo); /// this probably is not much of a problem when a 
> subroutine is this short
// it's the much-longer ones 
>   end;
> 
> begin
>   repeat
> begin
foobiee( ... ); /// ... that this logically comes first
>   littlefoobie;
>   writeln(thisfoo,'',thatfoo);
> end;
>   until thisfoo >= 25;
> end;
> 
> begin
>   dofoobie;
> end.
> 
> 

How would you put this into subroutines:


procedure very_long_initialization_routine;
// (var some_big_list_of_variables... )

begin
  Timer1.Enabled := false;
 
  do_this();
  do_that();  // now for the sake of argument, say this routine fires up a 
thread reading in 1s of file names through FindFirst/FindNext
  // now we need a long delay before calling do_foo() that would operate on 
that list, so
 
  Timer1.OnTimer := do_the_rest_of_initialization();
  Timer1.Delay   := 1; // pseudo-code, can't remember how was that exactly 
called
  Timer1.Enabled := true;
  // that's it, we need to split here to give message loop opportunity to do 
Application.ProcessMessages
end;

/// (and here we break variable locality...)

procedure do_the_rest_of_initialization;
begin
  do_foo(...);
  // rinse&repeat if you have more sections like that doing different things...
end;

One can of course have TTimer as locally created object in the 
very_long_initialization_routine, yes... but an
Application.ProcessMessages + sleep(100) loop is probably much easier to type 
(and debug, and read).

Not mentioning that probably loop would be a wee little (tiny) bit more precise 
than calling the Timer ?

(that of course YMMV and IMvhO)

el_es


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-05 Thread Michael Schnell

On 12/04/2014 04:24 PM, Lukasz Sokol wrote:
Or e.g. I run FindFirst/FindNext loop over a large number of files, or 
even if I delegate reading of a file to another procedure, still takes 
time while nothing else can happen... (although /that/ actually I can 
imagine doing in a thread). Then such Application.ProcessMessages is 
about the only option ?


A long winding loop (such as "FindNext" freezes the GUI and all TTimers 
if you don't include ProcessMessages.


If doing the loop in a Thread you can send status messages to the main 
(GUI) thread by means of TThread.Queue or Application.QueueAsyncCall. 
(You do know that you can't access the GUI from a worker thread.)


-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-05 Thread Michael Schnell

On 12/04/2014 04:24 PM, Lukasz Sokol wrote:
Executing a thread, which would TOO contain Sleep() in its Execute, 
and then calling into next part of the startup procedure ? 


When doing threads a completely different paradigm needs to be applied.
 - TTimer can't be used in a thread
 - sleep often is very appropriate in at thread, while sleep in the 
main thread freezes the GUI and all TTImers, and hence should not be used.


-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-04 Thread waldo kitty

On 12/4/2014 10:24 AM, Lukasz Sokol wrote:

(OnTimer execution has the same problem : inevitably splits the procedure into
more procedures, that can no longer use same local variables and stuff)


you can't make them subroutines of the subroutine?

eg:

program foobie;

procedure dofoobie;

var
  thisfoo : integer = 0;
  thatfoo : integer = 0;

  procedure littlefoobie;
  begin
inc(thisfoo,thatfoo);
inc(thatfoo);
  end;

begin
  repeat
begin
  littlefoobie;
  writeln(thisfoo,'',thatfoo);
end;
  until thisfoo >= 25;
end;

begin
  dofoobie;
end.


--
 NOTE: No off-list assistance is given without prior approval.
   Please *keep mailing list traffic on the list* unless
   private contact is specifically requested and granted.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-04 Thread Frederic Da Vitoria
2014-12-04 18:20 GMT+01:00 Paul Breneman :

> On 12/03/2014 04:51 PM, Paul Breneman wrote:
>
>> On 12/03/2014 04:37 PM, Terry A. Haimann wrote:
>>
>>> I have a program that starts some background processes and then needs to
>>> go to sleep for 15 seconds or so and then come back and check on their
>>> statuses.  So I used a loop like the following:
>>>
>>> EndTime := Now + EncodeTime(0, 0, 15, 0);
>>> While Now < EndTime do
>>>Application.ProcessMessages;
>>>
>>> The problem  is that the core this process runs on is running 60-80% cpu
>>> utilization.  Is there away to do something like this and not max the
>>> core out?  This computer is an i5 Desktop running Linux Mint 17-64.
>>>
>>> Thanks in advance,T.
>>>
>>
>> The quickest thing to do is to put Sleep(10) inside the while loop. That
>> will help you get longer battery life on a laptop and a cooler CPU!
>>
>> But I would normally use a separate thread.  There are a number of
>> examples here (see ExThread---):
>>http://turbocontrol.com/APro.htm
>> If you search CodeNewsFast you might be able to turn up a number on
>> explanations on why I recommend using a separate thread.
>>
>> Regards,
>> Paul
>> www.TurboControl.com
>>
>
> I'm replying a second time as my first reply didn't get posted (yet).
>
> Here is a message that has my (old) summary: :)
> http://codenewsfast.com/cnf/article/0/permalink.art-ng1824q786


FWIW, your previous message did reach me:

Received: by 10.152.234.229 with SMTP id uh5csp19639lac;
Wed, 3 Dec 2014 14:51:27 -0800 (PST)


-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-04 Thread Paul Breneman

On 12/03/2014 04:51 PM, Paul Breneman wrote:

On 12/03/2014 04:37 PM, Terry A. Haimann wrote:

I have a program that starts some background processes and then needs to
go to sleep for 15 seconds or so and then come back and check on their
statuses.  So I used a loop like the following:

EndTime := Now + EncodeTime(0, 0, 15, 0);
While Now < EndTime do
   Application.ProcessMessages;

The problem  is that the core this process runs on is running 60-80% cpu
utilization.  Is there away to do something like this and not max the
core out?  This computer is an i5 Desktop running Linux Mint 17-64.

Thanks in advance,T.


The quickest thing to do is to put Sleep(10) inside the while loop. That
will help you get longer battery life on a laptop and a cooler CPU!

But I would normally use a separate thread.  There are a number of
examples here (see ExThread---):
   http://turbocontrol.com/APro.htm
If you search CodeNewsFast you might be able to turn up a number on
explanations on why I recommend using a separate thread.

Regards,
Paul
www.TurboControl.com


I'm replying a second time as my first reply didn't get posted (yet).

Here is a message that has my (old) summary: :)
http://codenewsfast.com/cnf/article/0/permalink.art-ng1824q786


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-04 Thread Lukasz Sokol
Hi,

(for md as well as Michael)

On 04/12/14 08:35, Michael Schnell wrote:
> On 12/03/2014 11:37 PM, Terry A. Haimann wrote:
>> I have a program that starts some background processes and then
>> needs to go to sleep for 15 seconds or so and then come back and
>> check on their statuses.
> 
> A "more decent" way is to leave the current event and use a TTimer
> (e.g. with en event counting down seconds) and do the necessary stuff
> in the timer event.
> 

But sometimes it's totally not practical and worse than that, unmaintainable
to split the set order of execution of the startup procedure like that...

Executing a thread, which would TOO contain Sleep()  in its Execute, and then
calling into next part of the startup procedure ?

(OnTimer execution has the same problem : inevitably splits the procedure into 
more procedures, that can no longer use same local variables and stuff)

(say I need to load some library in OnCreate (or even in initialization), 
 [or be it that I want to load a library on demand, when user wants to use a 
feature]
that in turn takes some time to initialize itself and does not work properly if
called before some time passes; or if it's clever(er) gives us a status call;
but no other calls may be used in further of my program until the init is 
complete;
but I don't want the form to freeze while init is going on, but rather have 
e.g. a progress bar,
and maybe an error message on timeout;)

Or e.g. I run FindFirst/FindNext loop over a large number of files, 
or even if I delegate reading of a file to another procedure, still takes time
while nothing else can happen... (although /that/ actually I can imagine doing 
in a thread).

Then such Application.ProcessMessages is about the only option ?

> -Michael
> 
Lukasz


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-04 Thread Michael Schnell

On 12/03/2014 11:37 PM, Terry A. Haimann wrote:

I have a program that starts some background processes and then needs to
go to sleep for 15 seconds or so and then come back and check on their
statuses.


A "more decent" way is to leave the current event and use a TTimer (e.g. 
with en event counting down seconds) and do the necessary stuff in the 
timer event.


-Michael

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-03 Thread m...@rpzdesign.com
Simple, TThread.Execute ; override ;

Application process messages is SO Windows 3.1.

md

On 12/3/2014 5:51 PM, Paul Breneman wrote:
> On 12/03/2014 04:37 PM, Terry A. Haimann wrote:
>> I have a program that starts some background processes and then needs to
>> go to sleep for 15 seconds or so and then come back and check on their
>> statuses.  So I used a loop like the following:
>>
>> EndTime := Now + EncodeTime(0, 0, 15, 0);
>> While Now < EndTime do
>>Application.ProcessMessages;
>>
>> The problem  is that the core this process runs on is running 60-80% cpu
>> utilization.  Is there away to do something like this and not max the
>> core out?  This computer is an i5 Desktop running Linux Mint 17-64.
>>
>> Thanks in advance,T.
> 
> The quickest thing to do is to put Sleep(10) inside the while loop. That
> will help you get longer battery life on a laptop and a cooler CPU!
> 
> But I would normally use a separate thread.  There are a number of
> examples here (see ExThread---):
>   http://turbocontrol.com/APro.htm
> If you search CodeNewsFast you might be able to turn up a number on
> explanations on why I recommend using a separate thread.
> 
> Regards,
> Paul
> www.TurboControl.com
> 
> 
> -- 
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
> 

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-03 Thread Paul Breneman

On 12/03/2014 04:37 PM, Terry A. Haimann wrote:

I have a program that starts some background processes and then needs to
go to sleep for 15 seconds or so and then come back and check on their
statuses.  So I used a loop like the following:

EndTime := Now + EncodeTime(0, 0, 15, 0);
While Now < EndTime do
   Application.ProcessMessages;

The problem  is that the core this process runs on is running 60-80% cpu
utilization.  Is there away to do something like this and not max the
core out?  This computer is an i5 Desktop running Linux Mint 17-64.

Thanks in advance,  T.


The quickest thing to do is to put Sleep(10) inside the while loop. 
That will help you get longer battery life on a laptop and a cooler CPU!


But I would normally use a separate thread.  There are a number of 
examples here (see ExThread---):

  http://turbocontrol.com/APro.htm
If you search CodeNewsFast you might be able to turn up a number on 
explanations on why I recommend using a separate thread.


Regards,
Paul
www.TurboControl.com


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Lazarus and Application.ProcessMessages

2014-12-03 Thread Mattias Gaertner
On Wed, 03 Dec 2014 16:37:38 -0600
"Terry A. Haimann"  wrote:

> I have a program that starts some background processes and then needs to
> go to sleep for 15 seconds or so and then come back and check on their
> statuses.  So I used a loop like the following:


EndTime := Now + EncodeTime(0, 0, 15, 0);  
While (Now < EndTime) and not WaitingCancelled do begin
  Application.ProcessMessages;
  Sleep(10);
end;
 
> The problem  is that the core this process runs on is running 60-80% cpu
> utilization.  Is there away to do something like this and not max the
> core out?  This computer is an i5 Desktop running Linux Mint 17-64.


Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Lazarus and Application.ProcessMessages

2014-12-03 Thread Terry A. Haimann
I have a program that starts some background processes and then needs to
go to sleep for 15 seconds or so and then come back and check on their
statuses.  So I used a loop like the following:

EndTime := Now + EncodeTime(0, 0, 15, 0);  
While Now < EndTime do
  Application.ProcessMessages;

The problem  is that the core this process runs on is running 60-80% cpu
utilization.  Is there away to do something like this and not max the
core out?  This computer is an i5 Desktop running Linux Mint 17-64.

Thanks in advance,  T.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus