Previously I was using this check inside main procedure and it was taking more than 15000 msec.
Then I moved this checking to thread then it dropped to less than 3000 msec but even this is in a thread it causes delay in main procedure and app.
Here is the code sample:
Code: Select all
Procedure.b xPing(xIP.s,xPort)
Protected chkIP, PingRet.b
chkIP = OpenNetworkConnection(xIP.s,xPort,#PB_Network_TCP|#PB_Network_IPv4,100) ; havChekdDiffTimoutz
If chkIP
CloseNetworkConnection(chkIP)
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure xPingStaThread(Dummy.b)
Shared xPingStat.b
Protected tmp.l
DebugString("ThreadStarting")
Repeat
pingskip+1
tmp.l=ElapsedMilliseconds()
If pingskip=1
If xPing(#NAServer,21)
xPingStat=#True
Else
xPingStat=#False
EndIf
ElseIf pingskip>=600
pingskip=0
EndIf
tmp=ElapsedMilliseconds()-tmp.l
If tmp>13
DebugString(Str(tmp)+" AFISThreadedStat: "+Str(xPingStat))
EndIf
tmp=0
Delay(100)
ForEver
EndProcedure
Procedure Main()
Shared xPingStat.b
Repeat
SkipStat+1
;SomeCodeHere
If SkipStat=1
If xPingStat=#True
;SomeCodeHere
Else
;SomeCodeHere
EndIf
ElseIf SkipStat>=600
SkipStat=0
EndIf
Delay(100)
Forever
EndProcedure
;SomeCodeHere
Main()
;SomeCodeHere