Android Question Sleep(0) vs DoEvents (again)

Mickster

Active Member
Licensed User
Longtime User
Existing threads always say not to post but to start a new thread...seems a bit odd because one can end-up having to read multiple threads that cover a single issue :confused:

Anyway, I am pretty much a B4A newbie again after 10 years and really excited to be working with this awesome B4X ๐Ÿ‘๐Ÿ˜Ž๐Ÿ‘

We developed an app more than 10 years ago and it has been running constantly, in many locations, controlling industrial machinery.

Originally, we didn't anticipate an issue with higher screen resolutions coming along but now I have to tackle this issue and it's going well.

In the original code, there are quite a few DoEvents. Reading the latest documentation, it is recommended to replace these with Sleep(0) but if I do this, I get all kinds of complaints:

Error occurred on line: 10603 (Main)
java.lang.RuntimeException: Object should first be initialized (Label).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.TextViewWrapper.setTextSize(TextViewWrapper.java:121)
at phenix.thrive.main._callalertbox(main.java:5575)
at phenix.thrive.main._activity_resume(main.java:5550)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at phenix.thrive.main.afterFirstLayout(main.java:111)
at phenix.thrive.main.access$000(main.java:17)
at phenix.thrive.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

I accept the fact that the code is probably at fault but does it matter if I decide to stick with the deprecated DoEvents, as in, will it bite me down the road?

Regards,

Craig
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Do NOT post crashlogs as picture. It is text which you can copy. Post it as text in a quotetag

Hiding the full code is of no help for us to help you. How should we help here?

Upload a small project showing the issue.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
will it bite me down the road
Probably. See this post of mine
You will likely have to adapt your code to use WaitFors.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
How should we help here?

Well the code has been in constant use, around the world since 2012 but it doesn't like having DoEvents replaced by Sleep(0)
and so my above question was:
but does it matter if I decide to stick with the deprecated DoEvents, as in, will it bite me down the road?
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
Probably. See this post of mine
You will likely have to adapt your code to use WaitFors.
Cool....I shall investigate. Many thanks ๐Ÿ‘
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Upvote 0
Top