1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question ProgressDialogShow, DoEvents and Sleep(0)

Discussion in 'Android Questions' started by mmieher, May 10, 2019.

  1. mmieher

    mmieher 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,
    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 = 
                    rHeight = 
    End If
                rHeight = 
    End If
    Dim cli As Panel = CreateItemListItem(iRecord(0),iRecord(1),iRecord(3),iRecord(4), iRecord(2), 100%x, rHeight)
    End Sub
  2. j_o_h_n

    j_o_h_n 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.
  3. mmieher

    mmieher Active Member Licensed User

    Sleep(x) where x is any number does not work without DoEvents.
  4. Erel

    Erel Administrator 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.
    j_o_h_n and mmieher like this.
  5. mmieher

    mmieher 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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice