B4J Question how to continue process

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

how to slove system lag questtion !? My system will lag "interval ms" when i run this code ! :(

B4X:
public Sub test(interval As Int)
    Dim now As Long=DateTime.Now
    Do While True
        If (DateTime.Now-now)>interval Then
            Exit
        End If
    Loop
End Sub
 

Daestrum

Expert
Licensed User
Longtime User
It would help if you explained why you are using the code, so we can post alternate ways to achieve the same effect without tying the main thread up.
 
Upvote 0

jinyistudio

Well-Known Member
Licensed User
Longtime User
sorry ! following is my correct code : :oops:

B4X:
public Sub test(interval As Int) as int
   dim retn as int
   Dim now As Long=DateTime.Now
   Do While True
      if IsItRespone(data,20) then
         retn = 0 ' OK, I got a packet from RS-232
         exit
      else
        If (DateTime.Now-now)>interval Then
          retn = -1 ' NG, I haven't got a packet from RS-232
          exit
        End If
      End If
   
   Loop
   return retn
End Sub
 
Upvote 0
Top