100% cpu when printing

100% cpu when printing

Postby Davide » Fri Jan 12, 2007 1:32 am

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

Re: 100% cpu when printing

Postby Enrico Maria Giordano » Fri Jan 12, 2007 8:18 am

Try using

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8600
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: 100% cpu when printing

Postby Davide » Fri Jan 12, 2007 8:33 am

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

Re: 100% cpu when printing

Postby Enrico Maria Giordano » Fri Jan 12, 2007 8:43 am

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  Expand view
#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"


HB_FUNC( SLEEP )
{
    Sleep( hb_parnl( 1 ) );
}

#pragma ENDDUMP


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8600
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: 100% cpu when printing

Postby Davide » Fri Jan 12, 2007 5:22 pm

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

Re: 100% cpu when printing

Postby Enrico Maria Giordano » Fri Jan 12, 2007 5:30 pm

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

Re: 100% cpu when printing

Postby Davide » Fri Jan 12, 2007 6:12 pm

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

Re: 100% cpu when printing

Postby Enrico Maria Giordano » Fri Jan 12, 2007 7:32 pm

Agreed. But we have just seen how to deal with that situation. :D

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8600
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 49 guests