Alaska Software Inc. - waiting to create file pdf
Username: Password:
AuthorTopic: waiting to create file pdf
Salvatore Megna waiting to create file pdf
on Fri, 16 Feb 2018 17:51:30 +0100
Hi. In a my software I must wait that PDFCreator create a PDF.
Is there a method to wait that pdf file is totaly create?
I thinked this but this blocks many pc

    aDir := Directory( pFileName )

    If Len( aDir ) > 0
       nSize  := aDir[1,F_SIZE]
       nTimes := 0
       Do While nTimes < 10000
          Inkey(1)
          nTimes++

          aDir = Directory( pFileName )
          If nSize == aDir[1,F_SIZE]
             lTrovato := .t.
             EXIT
          Else
             nSize := aDir[1,F_SIZE]
          Endif
       Enddo
    Endif



Please help me
Carlos a Beling Re: waiting to create file pdf
on Fri, 16 Feb 2018 15:24:02 -0200
Hello Salvatore.
Good afternoon.
Take a look at the function Directory(). May be you are using it 
incorrectly.

May be you want to do this:

FUNCTION WaitForPDF(cCompleteFilePath)
LOCAL nElapsed
nElapsed := 0
do while nElapsed <= 500
    if FExists(cCompleteFilePath)
       exit
    endif
    Sleep(10)
enddo
RETURN (nElapsed <= 500)

Fraternally
Beling

Em 16/02/2018 14:51, Salvatore Megna escreveu:
>
> Hi. In a my software I must wait that PDFCreator create a PDF.
> Is there a method to wait that pdf file is totaly create?
> I thinked this but this blocks many pc
>
>     aDir := Directory( pFileName )
>
>     If Len( aDir ) > 0
>        nSize  := aDir[1,F_SIZE]
>        nTimes := 0
>        Do While nTimes < 10000
>           Inkey(1)
>           nTimes++
>
>           aDir = Directory( pFileName )
>           If nSize == aDir[1,F_SIZE]
>              lTrovato := .t.
>              EXIT
>           Else
>              nSize := aDir[1,F_SIZE]
>           Endif
>        Enddo
>     Endif
>
>
>
> Please help me
Andreas Gehrs-Pahl
Re: waiting to create file pdf
on Fri, 16 Feb 2018 15:35:41 -0500
Salvatore,

As Carlos wrote, you should use FExists() rather than Directory() to check 
for the existence of the file, and use Sleep() to not use 100% of the CPU 
cycles. In addition, I would suggest that you add some sort of event check
after the Sleep(), so that the application doesn't become unresponsive:

Function Wait_For_File(cPathName, cFileName)
LOCAL nEvent := xbeP_None, mp1, mp2, oXbp
LOCAL nWait  := 0
  for nWait := 1 to 600                  Wait 5 Minutes at most
     if FExists(cPathName + cFileName)
        return (.t.)
     else
        Sleep(50)                        Wait 1/2 a Second
        if NextAppEvent() # xbe_None
           while (nEvent := AppEvent(@mp1, @mp2, @oXbp, 0)) # xbe_None
              if ValType(oXbp) == 'O' .and. oXbp:Status() == XBP_STAT_CREATE
                 oXbp:HandleEvent(nEvent, mp1, mp2)
              endif
           enddo
        endif
     endif
  next nWait
return (.f.)

That way, you could also allow the user to cancel the wait, for example.

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[F]:   https://www.facebook.com/AbsoluteSoftwareLLC
Zdenko BielikRe: waiting to create file pdf
on Sat, 17 Feb 2018 19:10:38 +0100
Hi,

just add one next test after test of existence target file:
it will test/wait if file is not only created(exists), but if it is already 
accesible for other procceses than pdfcreator at the test' time.
I use it in this way in one my app, because without this while bigger/big 
report/file is created/generated, pdf file is although created, but still 
not yet ready for use/read/show - pdfcreator blocks it.

Trick is trying rename file to any temp-file and if it is 
successful(pdfcreator finished work yet), just rename it back.


cTempFile := (cPathName + 'temp.pdf')

...
     if FExists(cPathName + cFileName)
*         return (.t.)
        if ( FRename( (cPathName + cFileName), cTempFile ) == 0 )
           FRename( cTempFile, (cPathName + cFileName) )
           return (.t.)
         endif
     else
...


Regards,
                 Zdeno
Jim LeeRe: waiting to create file pdf
on Fri, 16 Feb 2018 21:21:11 +0100
why not run it in a Thread ?

   oThread := Thread():new()
   oThread:start( {|| Do_PDF_Print(x,y,z) } )
   SLEEP(10)
   DO WHILE oThread:active
      SLEEP(10)
   ENDDO
   oThread := NIL
Salvatore Megna Re: waiting to create file pdf
on Mon, 19 Feb 2018 09:48:55 +0100
Thanks for all
I think that I shall use fexist and sleep. I would use also FRename but 
if PDFCreator is setted to open file I can't to use FRename. With FCopy 
don't function?




Il 16/02/2018 17:51, Salvatore Megna ha scritto:
> 
> Hi. In a my software I must wait that PDFCreator create a PDF.
> Is there a method to wait that pdf file is totaly create?
> I thinked this but this blocks many pc
> 
>     aDir := Directory( pFileName )
> 
>     If Len( aDir ) > 0
>        nSize  := aDir[1,F_SIZE]
>        nTimes := 0
>        Do While nTimes < 10000
>           Inkey(1)
>           nTimes++
> 
>           aDir = Directory( pFileName )
>           If nSize == aDir[1,F_SIZE]
>              lTrovato := .t.
>              EXIT
>           Else
>              nSize := aDir[1,F_SIZE]
>           Endif
>        Enddo
>     Endif
> 
> 
> 
> Please help me
Zdenko BielikRe: waiting to create file pdf
on Mon, 19 Feb 2018 10:54:22 +0100
simply set showing just created document in PDFCreator to OFF
and open it form your app via RunShell or via ShellExecuteA / Open