Page 1 of 3

Application Not Responding while doing a long task

Posted: Fri May 01, 2009 7:53 am
by sudip
Hi,

I found that application is not responding (and it says so in Windows Task Manager) when it is doing a long task in a WHILE loop, E.g., converting a large dbf table to MySql.

Is there any solution for it?

Am I asking for Multi-threading!!! :)

TIA.

With best regards.

Sudip

Re: Application Not Responding while doing a long task

Posted: Fri May 01, 2009 9:20 am
by esgici
Hi Sudip

Please add a DO EVENTS command into your loop.

I hope that this will solve your problem.

As far as I know works on Multi-threading continues ( almost finished) in Harbour. Probably will be included in next release.

Regards

--

Esgici

Re: Application Not Responding while doing a long task

Posted: Fri May 01, 2009 9:32 am
by sudip
Hi Esgici,
esgici wrote: Please add a DO EVENTS command into your loop.

I hope that this will solve your problem.

As far as I know works on Multi-threading continues ( almost finished) in Harbour. Probably will be included in next release.
Thanks a lot! My problem is solved!!! :) (No multithreading required :lol: )

I wish if I can learn everyday something like this!!! :)

BTW, do you have any idea how to use incremental search in combobox. viewtopic.php?f=5&t=404

With best regards.

Sudip

Re: Application Not Responding while doing a long task

Posted: Fri May 01, 2009 11:13 am
by esgici
Hi
sudip wrote:... do you have any idea how to use incremental search in combobox.
I have MANY ideas on incremental search ;)

Unfortunately, until now I can't achieve any good result :(

I hope I'll open soon at least one to forum discussion.

Regards

--

Esgici

Re: Application Not Responding while doing a long task

Posted: Fri May 01, 2009 12:05 pm
by sudip
esgici wrote: I hope I'll open soon at least one to forum discussion.
Please do it ASAP. :)

I am waiting for it.

With best regards.

Sudip

Re: Application Not Responding while doing a long task

Posted: Fri May 01, 2009 3:48 pm
by Roberto Lopez
sudip wrote:
BTW, do you have any idea how to use incremental search in combobox. viewtopic.php?f=5&t=404
I usually solve that, with an OnChange procedure that takes value from edit control of the combo and search inside combo with a loop across all elements.

Regards,

Roberto.

Re: Application Not Responding while doing a long task

Posted: Wed May 06, 2009 2:19 pm
by CCH4CLIPPER
Hi Esgici

I have the same problem in processing a file with about 55,000 records.
The HMG apps appear to be hanging but it is actually working but does not dispaly the progress bar as expected :-(

This is even after adding DO EVENTS as follows :-




//--------------------------------------------------------------------------
STATIC FUNCTION ProcessCounter( hMeter, hText, hDlg, cMsg)
//--------------------------------------------------------------------------
MEMVAR Group_Exp, Index_1
MEMVAR lAdv_Header, Rept_Width, Pg_Ct,lDblSpace
MEMVAR sTot_Counter, nMain_Counter, Line, Most, Begin, PrnCounter,lSummary
memvar lMemoHeader,mDbfAlias //lh@02/11/02

LOCAL nRecNo
LOCAL nCount := 0


If Pg_Ct > 1
Line++
EndIf


DbGoTop()
WHILE !Eof()

If group_exp<>&index_1
GroupHead()
stot_counter:=0
EndIf
Loop()
stot_counter++
nMain_counter++
If Line >= MOST &&20
Line := BEGIN
Pg_Ct++

//lh 02/11/02
If lMemoHeader
HPrintMemo(1, &mDbfAlias->MEMOHEADER)
Else
Std_DispHead(rept_width,lAdv_Header)
EndIf
//lh@02/11/02 Std_DispHead(rept_width,lAdv_Header)
StdColHead()
EndIf // (Line=20)
prncounter++

nComplete := INT((prncounter/LASTREC()) * 100)
cComplete := LTRIM(STR(nComplete))

MainForm.Progress_1.Value := nComplete
MainForm.Label_001.Value := "Printing "+ ltrim(str(prncounter))+'/'+ltrim(str(lastrec()))+CHR(13)+ "Percentage completed "+cComplete + "%"
// 6/5/09
DO EVENTS
// 6/5/09


DbSkip()
ENDDO



Return nil // ProcessCounter()


Any help would be appreciated !

CCH
http://cch4clipper.blogspot.com

Re: Application Not Responding while doing a long task

Posted: Wed May 06, 2009 3:10 pm
by esgici
Hi CCH

Sorry, I can't understand the problem.

Because your code have many unknown things for me.

Only one point : Loop() function / procedure call line.

Although the () implied that is a UDF, the LOOP is a standard Clipper statement. If your Loop() line works as LOOP statement, lines between this and ENDDO newer will be executed. You are using keywords as identifier, such as BREAK. This isn't a good way and will be dangerous.

If possible, please send a problem concentrated code.

Regards

--

Esgici

Re: Application Not Responding while doing a long task

Posted: Wed May 06, 2009 5:11 pm
by sudip
Hello CCH,

I just created an example to test the functionality of DO EVENT command (although previously I tested it along with a MySql project).

I tested it with a table containing 417,033 records without any problem. Perhaps this small sample will be helpful to you :)

Code: Select all

#Include "MiniGui.ch"

Procedure Main()
	private cDbf := "", cTable := ""
   DEFINE WINDOW frmMain ;
      AT 5,5 ;
      WIDTH 640 ;
      HEIGHT 480;
      TITLE "Progress Bar Test" ;
      MAIN ;
      NOSIZE 


      @ 200, 100 button cmdSelectDbf caption "Select &Dbf" width 150 ;
         on click SelectDbf()

      @ 240, 100 label lblDbf value "" width 150

      @ 280, 100 button cmdProcess caption "&Process Table" width 150 ;
         on click ProcessDbf()

      @ 350, 100 PROGRESSBAR pgbExport ;
         VALUE 0 ;
         RANGE 0 , 100 		;
         WIDTH 300 			;
         HEIGHT 26 			;
         
         
      @ 400, 100 label lblRecord value "" autosize


      DEFINE MAIN MENU
         POPUP "&File"
            Item "E&xit"               action thiswindow.release()
         end popup
      END MENU

   END WINDOW

   frmMain.pgbExport.visible := .f.
   CENTER WINDOW frmMain
   ACTIVATE WINDOW frmMain

Return Nil



Function SelectDbf()
   cDbf := alltrim(GetFile({{"DBF Files","*.dbf"}},"Select a dbf file",,.f.,.f.))
   frmMain.lblDbf.caption := cDbf
   if len(alltrim(cDbf)) > 0
      if file(cDbf)
         use &cDbf
         lOpened := .t.
      endif
   endif
RETURN NIL



Function ProcessDbf()
   if empty(cDbf)
      MsgInfo("Please select a Dbf table")
      frmMain.cmdSelectDbf.setfocus
      return nil
   endif

   cTable := ALLTRIM(substr(cDbf,Rat('\',cDbf)+1))
   cTable :=substr(cTable,1,len(cTable)-4)
   
   frmMain.pgbExport.visible := .t.

   select &cTable
   go top
   do while !eof()
   	do events
      frmMain.pgbExport.value := recno()/reccount()*100
      frmMain.lblRecord.value := ltrim(str(recno()))+"/"+ltrim(str(reccount()))

      skip
   enddo
   frmMain.pgbExport.value := 0
   frmMain.pgbExport.visible := .f.

return nil
	
Please compile the code and run with your table. And please send your comments about the result.

With best regards.

Sudip

Re: Application Not Responding while doing a long task

Posted: Wed May 06, 2009 7:21 pm
by esgici
Hi Sudip

Good sample, clean and easy to understanding code :)

Thank you.

Regards

--

Esgici