Android Tutorial DoEvents deprecated and async dialogs (msgbox)

luciano deri

Active Member
Licensed User
Longtime User
I had use Doevents to show the rotate of Progressdialog.
B4X:
strquery = "SELECT * FROM tabella "
    dbcursor = Main.dbSql.ExecQuery(strquery)
    Dim documento As String
    For i = 0 To dbcursor.RowCount - 1
        dbcursor.position = i
        ProgressDialogShow("Lettura tabella in corso")
        DoEvents
    next
What instruction can i use instead DoEvents?
 

Star-Dust

Expert
Licensed User
Longtime User
When Erel said he could replace DoEvents, he did not say in the general sense but for some specific uses. In fact, for some uses, WaitFor and Sleep are optimized and save you code and design time.
It is not usable for all uses because they are not exactly matching. Continue to use DoEvents where necessary
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
You could use Sleep(0) but why are you calling ProgressDialogShow in a loop?

You should call it before you start the loop.

- Colin
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
I took it to mean that using DoEvents should be avoided wherever possible, so have replaced all DoEvents in my code with Sleep(0). Actually, I took the opportunity to think about whether I really needed each of them & as a result was able to remove a few as well.

In cases where you have a sub returning a value & you want to use Sleep, you can generally refactor the code so that it works. I haven't come across a situation where I couldn't replace a DoEvents with a Sleep(0).

- Colin.
 
Last edited:

luciano deri

Active Member
Licensed User
Longtime User
You could use Sleep(0) but why are you calling ProgressDialogShow in a loop?

You should call it before you start the loop.

- Colin
n the ProgressDialogShow show a value read in db, but if i call before cicle is same problem, without Doevent not rotate.
I see that Sleep(0), some time do return end exit cicle.
 
D

Deleted member 103

Guest
I would change your code like this.
B4X:
    strquery = "SELECT * FROM tabella "
    dbcursor = Main.dbSql.ExecQuery(strquery)
    Dim documento As String

    ProgressDialogShow("Lettura tabella in corso")
    Sleep(1000)

    For i = 0 To dbcursor.RowCount - 1
        dbcursor.position = i
       
        Do something ...
    Next
   
    ProgressDialogHide
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Ok, but i should rewrite all code to convert with this new method for access at db
It depends on which part is the bottleneck.
The async SQL methods are good when the query itself is the slow step.
If it is the for loop then you should write it like this:
B4X:
    ProgressDialogShow("Lettura tabella in corso")
    For i = 0 To dbcursor.RowCount - 1
        dbcursor.position = i
        If i Mod 500 = 0 Then Sleep(0)
        Do something ...
    Next
    ProgressDialogHide
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…