thread semaphore and rendezvous?

I have a class that runs asynchronously. I want to wait for that task to signal a completion.
is there a simple example that waits until the task completes and then continues?

Here’s a working demo:

http://files.tempel.org/RB/Thread%20Blocking%20Demo.rbp.zip

Look at BusyThread. The Run method (not the event) is where you can see that it starts a thread and then uses lock.Signal to wait for the thread to call lock.Release.

Though, this code will probably give you a UI…Thread exception in Xojo. Just remove the TellUser code from the Thread’s Run event, or let is print with System.DebugLog instead of adding it to the text field.

BTW, it may not be smart to block the main thread this way any more since Xojo started prohibiting doing UI in other threads: You’re effectively blocking the app from interacting with the user in any way while you wait for that thread to finished by using a semaphore (my example is from 2007, when this wasn’t an issue yet).

You better do not block your main thread and instead have the thread start a Timer from which you then perform the “main task” operations.