PROCEDURE Mainprocess Local Parallel as Parallel Parallel = NewObject("Parallel", "ParallelFox.vcx") Parallel.SetWorkerCount(Parallel.CPUCount) Parallel.BindEvent("UpdateProgress", _Screen.oMyHandler, "DisplayProgress") Parallel.StartWorkers() SCAN iFilename=ALLTRIM(Fullpath) oFilename=ALLTRIM(Newpath) RCNON=RCNO *Parallel.do("PS2PDF",'convert.prg',,iFilename,oFilename) Parallel.CallMethod("ps2pdf", This.Class, This.ClassLibrary,,,iFilename,oFilename,RCNON) ENDSCAN Parallel.Wait(.T.) Parallel.StopWorkers() ENDPROC>I have incorporated Parallel Fox in my VFP Code. Using a Single core in my I7 Machine I am able to process 2000 Records in 123 Seconds. Using parallel fox and using all cores of my CPU (i.e 8) I can do the same job with 96 Seconds.
>nRECCOUNTCONVERT=ALLTRIM(STR(RECCOUNT())) >cRECCOUNTCONVERT=' of '+ALLTRIM(STR(RECCOUNT())) > >T1=TIME() >Local loMyObject >loMyObject = CreateObject("MyObject") >_Screen.AddObject("oMyHandler", "MyHandler") >loMyObject.Mainprocess() >T2=TIME() >WAIT WINDOW T2-T1 >Return > >Define Class MyHandler as Custom >Procedure DisplayProgress >Lparameters lnPercent, lcMessage >_VFP.StatusBar = " (" + "%)" >EndProc >EndDefine > >DEFINE CLASS MyObject AS Custom >PROCEDURE Mainprocess >Local Parallel as Parallel >Parallel = NewObject("Parallel", "ParallelFox.vcx") >Parallel.StartWorkers() >SCAN >iFilename=ALLTRIM(Fullpath) >oFilename=ALLTRIM(Newpath) >RCNON=RCNO >Parallel.SetWorkerCount(Parallel.CPUCount) >Parallel.BindEvent("UpdateProgress", _Screen.oMyHandler, "DisplayProgress") >*Parallel.do("PS2PDF",'convert.prg',,iFilename,oFilename) >Parallel.CallMethod("ps2pdf", This.Class, This.ClassLibrary,,,iFilename,oFilename,RCNON) >ENDSCAN >Parallel.Wait(.T.) >Parallel.StopWorkers() >ENDPROC >** Convert ps files to PDF Using ps2PDF.Dll >PROCEDURE ps2PDF >PARAMETERS iFilename,oFilename,RCNON >DECLARE INTEGER _apCreate@0 IN ps2pdf.dll AS apCreate >DECLARE _apClose@4 IN ps2pdf.dll AS apClose INTEGER id >DECLARE INTEGER _apConvert@4 IN ps2pdf.dll AS apConvert INTEGER id >DECLARE INTEGER _apSetFunc@24 IN ps2pdf.dll AS apSetFunc INTEGER id, INTEGER code, INTEGER nOptVal1, INTEGER nOptVal2, STRING pOptVal1, STRING pOptVal2 >DECLARE INTEGER _apGetFunc@24 IN ps2pdf.dll AS apGetFunc INTEGER id, INTEGER code, INTEGER nOptVal1, INTEGER nOptVal2, STRING pOptVal1, STRING pOptVal2 >#define AP_Set_Output 3000 >#define AP_Set_Input 3001 >id=apCreate() >IF (id # 0) >apSetFunc(id, AP_Set_Input , 0, 0,iFilename, 0) &&input file. >apSetFunc(id, AP_Set_Output, 0, 0,oFilename, 0) &&output format and file. >apConvert(id) >apClose(id) >Sys(2335, 1) && disable unattended mode, allow UI >WAIT WINDOW RCNON NOWAIT >*Worker.UpdateProgress(RECNO(), "Converting..") >ENDIF >ENDPROC >ENDDEFINE > > > > > >