Android Question ProgressDialogShow, DoEvents and Sleep(0)


Active Member
Licensed User
Had a challenge getting the ProgressDialogShow2 to show. Read some posts about DoEvents. I get the warning "DoEvents is depricated. Use Sleep(0)".

Sleep(0) alone did not work for me.
DoEvents alone did not work for me.

Using BOTH does work. I guess its no big deal ...

Sub DisplayOneCategory(inID As Int)
    ProgressDialogShow2("Loading Products...",False)
    Dim qList As List
    SQLText = "SELECT iditem, mname, moos, mthc, mcbd FROM items WHERE idcategory = " & inID & _
                        " AND mhide = 0 ORDER BY items.msort"
    qList = DBUtils.ExecuteMemoryTable(Starter.SQL1,SQLText,Null,0)
    For j = 0 To qList.Size - 1
        Dim iRecord() As String = qList.Get(j)
        Dim rHeight As Int
        If Main.isTablet Then
            If Main.fLandscape Then
                rHeight = 180dip
                rHeight = 295dip
            End If
            rHeight = 145dip
        End If
        Dim cli As Panel = CreateItemListItem(iRecord(0),iRecord(1),iRecord(3),iRecord(4), iRecord(2), 100%x, rHeight)
End Sub


Active Member
Licensed User
How about 2 sleep(0) or one longer one?
if it worked it would be better to not use doevents I believe.
Upvote 0


Staff member
Licensed User
You should never use DoEvents.

Sleep doesn't need DoEvents to work. However the problem here is different. DBUtils.ExecuteMemoryTable is a blocking method. If it is too slow then don't use it. It is very simple to use the async SQL methods:
[B4X] SQL with Wait For

Note that you will not need to call Sleep or DoEvents after you switch to the async method. You do need to learn about resumable subs as the code flow is a bit different.
Upvote 0


Active Member
Licensed User
Thanks, Erel. I switched to the async method. Just an FYI, I did have to use Sleep(0) in order for the ProgressDialogShow2 to work. Not a problem.
Upvote 0