Android Question ProgressDialogShow, DoEvents and Sleep(0)

mmieher

Active Member
Licensed User
Longtime 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 ...

B4X:
Sub DisplayOneCategory(inID As Int)
   
    ProgressDialogShow2("Loading Products...",False)
    Sleep(0)
    DoEvents
   
    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
            Else
                rHeight = 295dip
            End If
        Else
            rHeight = 145dip
        End If
        Dim cli As Panel = CreateItemListItem(iRecord(0),iRecord(1),iRecord(3),iRecord(4), iRecord(2), 100%x, rHeight)
        clvProducts.Add(cli,iRecord(0))
    Next
   
    ProgressDialogHide
   
End Sub
 

j_o_h_n

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

Erel

B4X founder
Staff member
Licensed User
Longtime 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

mmieher

Active Member
Licensed User
Longtime 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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…