Erel: Seeing as YOU closed this thread: https://www.b4x.com/android/forum/threads/sleep-0-as-alternative-to-doevents.80127/#post-507622
so there can no longer be posts I am posting here
I am doing just what you have and the UI never updates.
PleaseWait Routine Code
Import Routine
Now using DoEvents the PleaseWait screen is update on every AddUpdatePlayer
Using Sleep routines Nothing shows at all.
so there can no longer be posts I am posting here
I am doing just what you have and the UI never updates.
PleaseWait Routine Code
B4X:
#Region ShowPleaseWait / ShowMessage / ShowMessages
Public Sub ShowScreen
If IsShowing = False Then ShowHidePleaseWait(True)
End Sub
Public Sub ShowPleaseWait(Line1 As String, Line2 As String, Line3 As String)
If mInitialized Then
mPW_Line1.Text = Line1
mPW_Line2.Text = Line2
mPW_Line3.Text = Line3
MarqueeTextForever(mPW_Line1)
MarqueeTextForever(mPW_Line2)
MarqueeTextForever(mPW_Line3)
If IsShowing = False Then ShowHidePleaseWait(True)
PumpMessageQueue
End If
End Sub
Public Sub ShowMessage(WhichLine As Int, Text As String)
If mInitialized Then
If WhichLine = 1 Then
mPW_Line1.Text = Text
MarqueeTextForever(mPW_Line1)
Else If WhichLine = 2 Then
mPW_Line2.Text = Text
MarqueeTextForever(mPW_Line2)
Else If WhichLine = 3 Then
mPW_Line3.Text = Text
MarqueeTextForever(mPW_Line3)
Else
Return
End If
If IsShowing = False Then ShowHidePleaseWait(True)
PumpMessageQueue
End If
End Sub
#End Region
Private Sub PumpMessageQueue_Wait(Duration As Long)
Dim Now As Long
Now = DateTime.now
' Log($"WaitHelper received: ${Duration} for loop: ${J}"$)
Sleep(Duration)
' Log($"WaitHelper slept: ${DateTime.Now-Now} ms"$)
CallSubDelayed(Me, "PumpMessageQueue_WaitComplete")
End Sub
Private Sub PumpMessageQueue
' Log("PumpMessageQueue - Attach:" &mPW_Main.Parent &" Visible:" &mPW_Main.Visible &" Enabled:" &mPW_Main.Enabled &" Frame-Visible:" &mPW_Frame.Visible &" (T/L):" &mPW_Frame.Top &" / " &mPW_Frame.Left)
' mPW_Main.BringToFront
' mPW_Frame.BringToFront
'
' mPW_Main.Enabled = True
' mPW_Main.Visible = True
#if _UseSleep_
Log("PumpMessageQueue - DoEvents:" &mDoEvents &" Every:" &mEvery &" EveryCnt:" &mEveryCnt)
' If mEvery = 0 Then
' mEvery = 1
'
' DoEvents
' End If
PumpMessageQueue_Wait(1000)
Wait For PumpMessageQueue_WaitComplete
Sleep(500)
#Else
' Log("PumpMessageQueue - DoEvents:" &mDoEvents &" Every:" &mEvery &" EveryCnt:" &mEveryCnt)
If mDoEvents Then
If mEvery > 0 Then
If mEvery > mEveryCnt Or mEveryCnt = 0 Then
DoEvents
End If
If mEvery > mEveryCnt Then
mEveryCnt = 0
Else
mEveryCnt = mEveryCnt + 1
End If
Else
DoEvents
End If
End If
#end if
End Sub
Import Routine
B4X:
#Region AddUpdatePlayer
Private Sub AddUpdatePlayer(PleaseWait As cPleaseWait, FWID As Long, Import_Player As cImport_Player) As Int
Dim NewFWPlayer As cPlayerRecord
Dim FoundPlayer As cPlayerRecord
NewFWPlayer.Initialize
FoundPlayer.Initialize
If FoundPlayer.FindPlayerByNameOrScoringID(FWID, Import_Player.Name, Import_Player.ScoringID) Then
FoundPlayer.Average = Import_Player.Average
FoundPlayer.Position = Import_Player.Position
FoundPlayer.Team = Import_Player.Team
FoundPlayer.Lane = Import_Player.Lane
If Import_Player.LaneIsPassed = False Then
If TeamLanes.Size > 0 Then
If Import_Player.Team > 0 And Import_Player.Team <= TeamLanes.Size Then
Import_Player.Lane = TeamLanes.Get(Import_Player.Team - 1)
FoundPlayer.Lane = Import_Player.Lane
Else
FoundPlayer.Lane = 99
End If
Else
If Import_Player.Team > 0 And Import_Player.Team <= TeamNumbers.Length Then
For i = 0 To TeamNumbers.Length-1
If TeamNumbers(i) = Import_Player.Team Then
Import_Player.Lane = LaneNumbers(i)
Exit
End If
Next
FoundPlayer.Lane = Import_Player.Lane
Else
FoundPlayer.Lane = 99
End If
End If
End If
PleaseWait.ShowMessages(Array As Int(2, 3), Array As String(Chr(9) &"Updating Player", Chr(9) &Chr(9) &FoundPlayer.Name))
#if Debug
Log(" Updating Player:" &Import_Player.Name &" Avg:" &Import_Player.Average &" Team/Posn:" &Import_Player.Team &"." &Import_Player.Position &" Lane:" &Import_Player.Lane &" SexIsMale:" &Import_Player.SexIsMale)
#end if
If FoundPlayer.AddUpdate Then Return 1
Return 0
End If
NewFWPlayer.Clear
NewFWPlayer.MakePlayer
NewFWPlayer.FrameWorkID = FWID
NewFWPlayer.Name = Import_Player.Name
NewFWPlayer.ScoringID = Import_Player.ScoringID
NewFWPlayer.setSex(Import_Player.SexIsMale)
NewFWPlayer.Average = Import_Player.Average
NewFWPlayer.Team = Import_Player.Team
NewFWPlayer.Position = Import_Player.Position
NewFWPlayer.Lane = Import_Player.Lane
If Import_Player.LaneIsPassed = False Then
If TeamLanes.Size > 0 Then
If Import_Player.Team > 0 And Import_Player.Team <= TeamLanes.Size Then
Import_Player.Lane = TeamLanes.Get(Import_Player.Team - 1)
NewFWPlayer.Lane = Import_Player.Lane
Else
FoundPlayer.Lane = 99
End If
Else
If Import_Player.Team > 0 And Import_Player.Team <= TeamNumbers.Length Then
For i = 0 To TeamNumbers.Length-1
If TeamNumbers(i) = Import_Player.Team Then
Import_Player.Lane = LaneNumbers(i)
Exit
End If
Next
NewFWPlayer.Lane = Import_Player.Lane
Else
NewFWPlayer.Lane = 99
End If
End If
End If
PleaseWait.ShowMessages(Array As Int(2, 3), Array As String(Chr(9) &"Adding Player", Chr(9) &Chr(9) &NewFWPlayer.Name))
#if Debug
Log(" Adding Player:" &Import_Player.Name &" Avg:" &Import_Player.Average &" Team/Posn:" &Import_Player.Team &"." &Import_Player.Position &" Lane:" &Import_Player.Lane &" SexIsMale:" &Import_Player.SexIsMale)
#end if
If NewFWPlayer.AddUpdate Then
If Import_Player.SexIsUndetermined Then
mUndeterminedPlayers.Add(NewFWPlayer.RecordID)
End If
Return 2
End If
Return 0
End Sub
#end Region
Now using DoEvents the PleaseWait screen is update on every AddUpdatePlayer
Using Sleep routines Nothing shows at all.