The only reason that bar will run before foo is finished it if foo is a resumable sub.
If it is use Wait For (like line 3) to wait for foo to finish.
Take a look at the tutorial
New video tutorial: Resumable subs is a new feature added in B4J v5.50 / B4i v4.00 / B4A v7.00. It dramatically simplifies the handling of asynchronous tasks. (This feature is a variant of stackless coroutines.) The special feature of resumable subs is that they can be paused, without...