STATIC e THREAD STATIC
Enviado: 14 Set 2016 18:02
Pessoal,
Qual é a diferença entre STATIC e THREAD STATIC
Qual é a diferença entre STATIC e THREAD STATIC
Código: Selecionar todos
STATIC wTelas := {}
Código: Selecionar todos
THREAD STATIC wTelas := {}
Código: Selecionar todos
FUNCTION MAIN
LOCAL cTeste1:=Space(8), cTeste2:=Space(8), cTeste3:=Space(8)
oInatividade := ClInatividade():New()
oInatividade:Start( .T., 5, {|| Put( Time() )}, "A")
@ 05,00 GET cTeste1
@ 06,00 GET cTeste2 WHEN {|| oInatividade:End("A") }
@ 07,00 GET cTeste3 WHEN {|| oInatividade:Start( .T., 30, {|| Put( Time() )}, "A") }
READ
RETURN Nil
FUNCTION Put( cVar )
LOCAL nRow, nCol, oElemento
nRow:=Row()
nCol:=Col()
FOR EACH oElemento IN GetList
WITH Object oElemento
IF :name = "cTeste3"
:Varput( cVar )
:UpdateBuffer()
:Display()
ENDIF
END
NEXT
SETCURSOR(1)
SetPos(nRow, nCol)
RETURN Nil
#pragma BEGINDUMP
#include "windows.h"
#include "time.h"
#include "hbapi.h"
HB_FUNC( PEGAINATIVIDADE )
{
LASTINPUTINFO lpi;
lpi.cbSize = sizeof (LASTINPUTINFO);
GetLastInputInfo (&lpi);
hb_retnd( ( DOUBLE ) ( GetTickCount() - lpi.dwTime ) / CLOCKS_PER_SEC );
}
#pragma ENDDUMP
Código: Selecionar todos
*****************************************************
* Função para verificar ociosidade de teclado e mouse
* executa um bloco de função/procedure
* ---------------------------------------------------
* Autor : Alexandre Simões
* Data : 13/10/2016
* Versão: 1.1
*****************************************************
#include "hbclass.ch"
THREAD STATIC nIdleTimeInatividade
THREAD STATIC aIdle:={}
CREATE CLASS ClInatividade
METHOD Start( lInicio, nTempo, bBloco, cIdentificador )
METHOD End( cIdentificador )
METHOD Inatividade( nTempo, nIdleTimeInatividade, bBloco )
ENDCLASS
METHOD Start( lInicio, nTempo, bBloco, cIdentificador ) CLASS ClInatividade
LOCAL oElemento
hb_Default(@lInicio, .T.)
hb_Default(@nTempo, 10)
hb_Default(@bBloco, {|| lInicio:=lInicio })
hb_Default(@cIdentificador, "A")
IF lInicio
nIdleTimeInatividade := hb_IdleAdd( {|| ::Inatividade( nTempo, nIdleTimeInatividade, bBloco ) } )
aAdd( aIdle, {nIdleTimeInatividade, cIdentificador} )
ELSE
::End( cIdentificador )
ENDIF
RETURN .T.
METHOD End( cIdentificador ) CLASS ClInatividade
LOCAL oElemento
hb_Default(@cIdentificador, "T")
FOR EACH oElemento IN aIdle
IF cIdentificador = "T"
IF oElemento[1] != Nil
hb_IdleDel( oElemento[1] )
ENDIF
ELSE
IF oElemento[1] != Nil .AND. oElemento[2] = cIdentificador
hb_IdleDel( oElemento[1] )
ENDIF
ENDIF
NEXT
IF cIdentificador = "T"
aIdle := {}
ELSE
FOR EACH oElemento IN aIdle
IF oElemento[1] != Nil .AND. oElemento[2] = cIdentificador
hb_IdleDel( oElemento[1] )
hb_ADel( aIdle, oElemento:__enumIndex() , .T. )
ENDIF
NEXT
ENDIF
RETURN .T.
METHOD Inatividade( nTempo, nIdleTimeInatividade, bBloco ) CLASS ClInatividade
IF Round(PegaInatividade(),0) >= nTempo .AND. ValType( bBloco ) = "B"
hb_IdleReset( nIdleTimeInatividade )
Eval ( bBloco )
ENDIF
hwg_DoEvents()
hb_IdleSleep( 0 )
RETURN Nil