Bug? Attention with Sleep(0)

D

Deleted member 103

Guest
Hi,

To all B4x users!
Please check carefully what happens if you exchange DoEvents with Sleep(0).
In my app the entries in a ScrollView2D were added twice. :mad:

cmm_sleep.jpg


cmm_DoEvents.jpg
 
D

Deleted member 103

Guest
This is not a bug. Sleep(0) behavior is not identical to DoEvents.
If this is not an bug, then I did not understand the function Sleep(0). :(

In my case, I have DoEvents exchanged immediately after ProgressDialogShow2 with Sleep(0), and that caused the error.
I find that the function DoEvents should not be marked as deprecated, because otherwise the B4x-User is lent the function no longer to use or as I, the function to exchange with Sleep(0).

In any case, I have now learned my lesson, and will not exchange DoEvents with any other function.
Except there is a function which does the same. ;)
 

MarcoRome

Expert
Licensed User
Longtime User
I used Doevent in the past to make an interface refresh. I replaced with Sleep (0) and i had no problem
 

LucaMs

Expert
Licensed User
Longtime User
But i see that Erel has answered your question ( HERE ), and seem that work or no ?
He has shown different ways to rewrite my sample code.

From my point of view this means that you can definitely use Sleep ALSO for updating the GUI but you can not simply replace DoEvents with Sleep(0) (and I have not even been able to create a routine that replaces DoEvents used for that purpose).
 
D

Deleted member 103

Guest
I used Doevent in the past to make an interface refresh. I replaced with Sleep (0) and i had no problem
I thought that too.
I've spent a lot of time trying to find the error, then I just swapped Sleep(0) with DoEvents and the error was gone.
I think that the programmer with the DoEvents still has a control over the program sequence, but with Sleep(0) but no more, and that is a big error source.

Therefore here again my request:
DoEvents should not be marked as deprecated, As long as a comparable function does not exist.
I just do not want the same error to happen to other B4x users as well. :(

But, we said this is just my wish,
and perhaps also the wish of a few thousands B4x users. ;)
 

LucaMs

Expert
Licensed User
Longtime User
DoEvents is potentially "dangerous".

The reason is that it is different from the same VB.Net command and the programmer is inclined to think that he can use it in the same way.
As far as I understand, the main difference is that VB.Net DoEvents gives control to the operating system; this does not happen with b4a so if you run a loop that takes a long time (it seems 5 seconds) the system might consider your app locked and kill it.

So I think if loop execution takes less than 5 seconds you can use DoEvents quietly.

Perhaps you can also create one (or two) routines that use Sleep and Wait For to get a general function that performs the task as we mean; I tried a few days ago, but then I did not insist. This can be a challenge for all of us: will someone succeed in creating such a function? :)
 
Last edited:
Top