Her the Thread Func:
function ThreadLoop( nThreadInfoId as ptr ) as dword _wincall
local oInfo as ADESocketInfoSemaphore
local nRetVal := 0 as dword
if .not. nThreadInfoId = NULL_PTR
oInfo := object( _cast, nThreadInfoId )
if .not. oInfo == NULL_OBJECT
if .not. oInfo:Connection == NULL_OBJECT
do while oInfo:Connection:Execute( oInfo )
_FuncLOG( "SocketThread Pre Sleep" )
Sleep( oInfo:ThreadTimeOut )
_FuncLOG( "SocketThread Post Sleep" )
end do
_FuncLOG( "SocketThread End" )
end if
end if
end if
return nRetVal
Here the Creation of the Thread:
method InitConnectionThread( poItem, poInfo, nTimeOut )class
ADESocketEngine
local lRetVal := false as logic
local oItem as ADESocketConnection
local oInfo as ADESocketInfoSemaphore
local pInfoPtr as ptr
Default( @nTimeOut, self:ThreadTimeOut )
oItem := poItem
oInfo := poInfo
if .not. oItem == NULL_OBJECT
if .not. oInfo == NULL_OBJECT
pInfoPtr := ptr( _cast, oInfo )
oInfo:ThreadTimeOut := nTimeOut
oInfo:ptrThread := CreateVOThread( NULL, ; // No Security
0, ; // Default Stack size
@ThreadLoop(), ; // Entry Point
pInfoPtr, ; // Socket Info
CREATE_SUSPENDED, ; // Do not run immediately
ptr( _cast, @oInfo:ThreadID ) ) // Receives thread Id
if .not. oInfo:ptrThread == NULL
SetThreadPriority( oInfo:ptrThread, THREAD_PRIORITY_LOWEST )
ResumeThread( oInfo:ptrThread )
end if
lRetVal := true
end if
end if
return lRetVal