Wish "Wait For" optionally starts a new thread

JohnK

Active Member
Licensed User
Longtime User
I like the new "Wait For" feature (I just upgraded from v3.2), but see that it does its best when used calling B4A code, where a hard loop can be interspersed with sleep's; as in the countdown code sample.

However, when a long "external" process is started, the UI gets blocked. It would seem to me that the mechanisms/code paradigms used in the "wait for" could be extended to optionally start the process on a non UI thread; ie a new thread.

For example, I have just coded an app that calls shell scripts, some of which take over 10s to complete, and the UI gets stalled during the call. Touching the screen during this time also triggers the app not responding, wait/kill message.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
You should use ShellAsync like so:
B4X:
Dim p As Phone
Wait For (p.ShellAsync("ping", Array As String("-c", "1", "b4x.com"))) Complete (Success As Boolean, ExitValue As Int, StdOut As String, StdErr As String)
If Success Then
    Log(ExitValue)
    Log("Out: " & StdOut)
    Log("Err: "&  StdErr)
Else
    Log("Error: " & LastException)
End If
 

JohnK

Active Member
Licensed User
Longtime User
More information please. What are you doing that blocks the main thread for a long time?
I am calling numerous/different shell commads , some of which take a long time. A couple of examples include, but are in noway limited to:
B4X:
dumpsys;
busybox traceroute www.google.com;
ping -c 5 www.google.com;

Wait For has nothing to do with threads.
I never said it did :confused: However, I can see how a similar coding pattern could be used, but of course, I would not wish to limit any final soln.;)

The reason I saw the similarity, is in the way a "sleep" returns code execution back to the previous calling routine, similar to how starting a new thread would also behave.
 

JohnK

Active Member
Licensed User
Longtime User
Please ignore the below....:oops:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You should use ShellAsync like so:
The problem is not in calling shell async. I have that working with much more complex scripts, its the fact that the process blocks the main/UI thread; in a few cases its because the scripts are complex.

Try it for yourself with something like 20+ pings instead of only a single solitary one. Have a few UI elements and try to interact while the ping is occurring.
 
Last edited:
Top