Thread on FWH

Post Reply
yury
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Thread on FWH

Post by yury »

Hello Mr.Antonio,

In this topic:

http://forums.fivetechsupport.com/viewt ... =3&t=10439

I read is not possible use mult-thread in FWH, but you ask for what
need this...

Please, see the code below:

Code: Select all

//------------------------------------------------------------------------------
Function Test()

MsgProgres('Executing SQL query...','Wait, please...',{|| Query() },.F.)

SELECT TEMP
GO TOP
BROWSE()

return
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
FUNCTION Query()
cSqlComand = "SELECT ID,Name,City,Country,Phone  FROM tbCustomers ORDER BY Name"
USE 'tbCustomers' AS cSqlComand ALIAS 'TEMP' VIA 'MySQL'
RETURN
//---------------------------------------------------------------------------------


//---------------------------------------------------------------------------------
FUNCTION MsgProgres(cCaption,cTitle,bAction)

LOCAL oDlg
LOCAL nWidth:=0

PRIVATE nContx:=0, oTimerx, oProgress

DEFINE DIALOG oDLG FROM 01,01 TO 09,41 TITLE cTitle STYLE DS_MODALFRAME

oProgress = TProgress():New(02,01,oDlg,0,,,.F.,.F.,140,10)

nWidth=oDLG:nRight-oDLG:nLeft

oDlg:bStart = {|| Eval(bAction,oDlg),; 
                  oTimerx:End()     ,; 
                  oDlg:End()        ,; 
                  SysRefresh()       }


oDlg:bPainted = {|hdc| oDlg:Say(01,02,xPadr(cCaption,nWidth)), SysRefresh() }

ACTIVATE DIALOG oDlg CENTER ON INIT (xInic(oDlg),oTimerx:Activate(),SysRefresh())                         

RETURN                               
//---------------------------------------------------------------------------------

//---------------------------------------------------------------------------------
FUNCTION xInic(oDlg)
DEFINE TIMER oTimerx OF oDlg INTERVAL 1 ACTION (oProgress:SetPos(++nContx),;
                                                nContx:=IF(nContx>150,0,nContx),;
                                                SysRefresh())
RETURN
//---------------------------------------------------------------------------------
 
I need start another thread because a SQL query make a current thread busy
and the timer of the progress bar dont work...

In this case, I will call a timer from second thread...

Any sugestion ?

regards
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Thread on FWH

Post by Antonio Linares »

Yuri,

Please try it this way:

Code: Select all

#include "FiveWin.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg TITLE "Please wait..."

   ACTIVATE DIALOG oDlg NOWAIT CENTERED

   cSqlComand = "SELECT ID,Name,City,Country,Phone  FROM tbCustomers ORDER BY Name"
   USE 'tbCustomers' AS cSqlComand ALIAS 'TEMP' VIA 'MySQL'

   oDlg:End()

   SELECT TEMP
   GO TOP
   BROWSE()

return nil 
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
yury
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Re: Thread on FWH

Post by yury »

Hello Mr.Antonio,

In time I am already make this way (with a static message), but what I
wanted was a progress bar refreshed by action timer , but it is only possible
with a mult-thread support, what isn't yet avaliable

anyway, many thanks for your help and attention

regards
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
yury
Posts: 56
Joined: Wed May 23, 2007 2:01 pm

Re: Thread on FWH

Post by yury »

Hello Enrico,

I am trying to use a timer (see code in the top of the post), but when the SQL query is being
executed the main thread stays busy, and turn off the timer, only turn on when the SQL query
finish (because the same thread is used for SQL query and for the timer)

In this case would be necessary start a second thread (mult-thread), but it is not yet available in FHW (as far as I know)

regards
Yury Marcelino Al
yury030575@yahoo.com.br
vimansca@vimansca.com.br
Leme / SP - Brasil
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Thread on FWH

Post by Antonio Linares »

Yuri, Enrico,

What it is stopping us from using a TIMER is the USE command itself:

USE 'tbCustomers' AS cSqlComand ALIAS 'TEMP' VIA 'MySQL'

as it does not call to SysRefresh() (or an equivalent one) so the Windows messages are not processed in the meantime, thus the TIMER does not receive any event.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply