Page 1 of 1
100% cpu when printing
Posted: Fri Jan 12, 2007 1:32 am
by Davide
Hi All,
the sample below puts the CPU at 100% with FWH 27 (March 06) - xH 0.99.60 - Bcc 5.5
The time consuming process is not "oPrn:Say()", but "PAGE/ENDPAGE"
Does this happens with latest FWH also ?
How can this be solved ?
Thanks,
Davide
Code: Select all
#include "Fivewin.ch"
function Main() // Test 100% CPU
Local oPrn,i
PRINT oPrn NAME "Test" FROM USER PREVIEW
if Empty( oPrn:hDC ) ; return nil ; endif
For i := 1 to 5000
SysRefresh() // This does not help
PAGE
oPrn:Say( 100, 100, Str(i) )
ENDPAGE
Next i
ENDPRINT
Return nil
Re: 100% cpu when printing
Posted: Fri Jan 12, 2007 8:18 am
by Enrico Maria Giordano
Try using
instead of SysRefresh(). Anyway the process will be slowed down and I don't know if it worth the while.
EMG
Re: 100% cpu when printing
Posted: Fri Jan 12, 2007 8:33 am
by Davide
Enrico,
Try using HB_IdleSleep( 0.001 )
Does this means that latest FWH do have the same behaviour ?
HB_IdleSleep() is not applicable because the sample runs for 2 minutes instead of 10 seconds.
Thank you,
Davide
Re: 100% cpu when printing
Posted: Fri Jan 12, 2007 8:43 am
by Enrico Maria Giordano
Davide wrote:Enrico,
Try using HB_IdleSleep( 0.001 )
Does this means that latest FWH do have the same behaviour ?
Yes.
Davide wrote:HB_IdleSleep() is not applicable because the sample runs for 2 minutes instead of 10 seconds.
Try Sleep( 1 ).
Code: Select all
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
HB_FUNC( SLEEP )
{
Sleep( hb_parnl( 1 ) );
}
#pragma ENDDUMP
EMG
Re: 100% cpu when printing
Posted: Fri Jan 12, 2007 5:22 pm
by Davide
EnricoMaria wrote:Try Sleep( 1 ).
YES!, this one works much better. It still slow down the process, but I can call it just before PAGE and after ENDPAGE (and the real life is not like the sample above).
Maybe it could be added to Printer.Prg - What do you think ? - Do you see any contraindication doing so ?
My concern is: if there is already a sleep() function in Kernel32.dll, why the need for developing a SysRefresh() or HB_IdleSleep() ?
Thank you so much!
Davide
Re: 100% cpu when printing
Posted: Fri Jan 12, 2007 5:30 pm
by Enrico Maria Giordano
Davide wrote:EnricoMaria wrote:Try Sleep( 1 ).
YES!, this one works much better. It still slow down the process, but I can call it just before PAGE and after ENDPAGE (and the real life is not like the sample above).
Or you may call it each n iterations.
Davide wrote:Maybe it could be added to Printer.Prg - What do you think ? - Do you see any contraindication doing so ?
I don't know. The 100% CPU behavior has never been a problem for me. I prefer maximum speed of print generation process.
EMG
Re: 100% cpu when printing
Posted: Fri Jan 12, 2007 6:12 pm
by Davide
EnricoMaria wrote:I don't know. The 100% CPU behavior has never been a problem for me. I prefer maximum speed of print generation process.
unless you want to install your application on a Terminal Server. If different users print simultaneously the server may sit down ...
Re: 100% cpu when printing
Posted: Fri Jan 12, 2007 7:32 pm
by Enrico Maria Giordano
Agreed. But we have just seen how to deal with that situation.
EMG