Call method and wait for thread

How do I make a method that institutes a thread that can make the method wait for the thread to finish up.

Thanks

The whole point of a thread is precisely to not wait. But if you really want to do what you describe, you set a variable with enough scope for the thread to access it when finished, and in the method you place a while/wend waiting for the variable to change state. It is usually done through a timer, though, rather than waiting in a method.

Thanks. So you are saying I should probably use a timer? Despite using Xojo for a year and a half, I will admit I do not have experience with threads.

Thanks

It depends.
Is your process intensive to the point where it’d lock up the interface?
Yes? Thread it.
No? Procedural operations would be fine.

If you’re waiting for a thread, remember to include a progress bar.

[quote=121445:@Tim Parnell]It depends.
Is your process intensive to the point where it’d lock up the interface?
Yes? Thread it.
No? Procedural operations would be fine.

If you’re waiting for a thread, remember to include a progress bar.[/quote]
Okay, that makes a lot of sense. Thanks

I have never had any problems with the app locking up from intense processing before. So that will explain why I have no experience with it. Actually, coming to think about it I have had this but I massively optimised the code which fixed well. I realise though that sometimes this cannot be the case. Thanks

As Tim told you, the rule is, when a process freezes the interface, chances are you need a thread.

Now, the timer comes to monitor the end of the thread. In the scheme I gave you, at the end of the thread, you place something like a threadfinished boolean property. The timer monitors every 100th of a second or so the value of threadfinished. When it turns true, you do what you have to do.

That way you do not hold your interface while the thread executes.

You really have to think of the end of the thread as just an event. But in terms of program, as it is not procedural, you must conceive your program in a modular way and make sure the user can still operate fine while the thread works.

[quote=121457:@Michel Bujardet]As Tim told you, the rule is, when a process freezes the interface, chances are you need a thread.

Now, the timer comes to monitor the end of the thread. In the scheme I gave you, at the end of the thread, you place something like a threadfinished boolean property. The timer monitors every 100th of a second or so the value of threadfinished. When it turns true, you do what you have to do.

That way you do not hold your interface while the thread executes.

You really have to think of the end of the thread as just an event. But in terms of program, as it is not procedural, you must conceive your program in a modular way and make sure the user can still operate fine while the thread works.[/quote]
Thanks