100% cpu when printing

Post Reply
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

100% cpu when printing

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: 100% cpu when printing

Post by Enrico Maria Giordano »

Try using

Code: Select all

HB_IdleSleep( 0.001 )
instead of SysRefresh(). Anyway the process will be slowed down and I don't know if it worth the while.

EMG
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: 100% cpu when printing

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: 100% cpu when printing

Post 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
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: 100% cpu when printing

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: 100% cpu when printing

Post 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
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: 100% cpu when printing

Post 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 ...
Post Reply