Page 1 of 1

Question about using LOOP

Posted: Wed Jun 13, 2007 1:42 pm
by driessen
Hello,

In my application, I use OLE to work together with MS-Word.

While working in Word, my application needs to wait until a button is pushed which end Word.

For waiting, I use this code :

Code: Select all

      DO WHILE .T.
         IF VActive
            SYSREFRESH()
            LOOP
         ENDIF
         EXIT
      ENDDO
When VActive = .F., the loop is ended and my application continues.

While my application is waiting, I often notice that the processor is used 100 %. This is eventually slowing down other running applications.

Is there a possibility to prevent that the processor is used for 100 % ?

I use Windows XP Professional and Microsoft Office 2003. My PC has 1 GB RAM.

Thanks a lot for any help.

Re: Question about using LOOP

Posted: Wed Jun 13, 2007 2:44 pm
by Enrico Maria Giordano
Try replacing SYSREFRESH() with

Code: Select all

HB_IDLESLEEP( 1 )
EMG

Posted: Wed Jun 13, 2007 3:33 pm
by driessen
EnricoMaria,

Thanks for you help.

I tried it, but if I push the button after having worked in Word, my application hangs completely.

Re: Question about using LOOP

Posted: Wed Jun 13, 2007 3:41 pm
by Enrico Maria Giordano
Then try using SLEEP() instead of HB_IDLESLEEP():

Code: Select all

#pragma BEGINDUMP

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


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

#pragma ENDDUMP
EMG

Posted: Wed Jun 13, 2007 9:13 pm
by driessen
EnricoMaria,

Thanks a lot. Your suggestion just works fine.

Problem solved.