# A way to wait for threads to complete using system.util. invokeAsynchronous?

**URL:** <https://forum.inductiveautomation.com/t/a-way-to-wait-for-threads-to-complete-using-system-util-invokeasynchronous/95090>\
**Category:** Ignition\
**Tags:** vision, ignition81, scripting\
**Created:** [August 23, 2024, 4:27pm UTC](https://forum.inductiveautomation.com/t/a-way-to-wait-for-threads-to-complete-using-system-util-invokeasynchronous/95090 "2024-08-23T16:27:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Novikov](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gregory_novikov/32/66734_2.png) [@Gregory\_Novikov](https://forum.inductiveautomation.com/u/Gregory_Novikov)\
**Post date:** [August 23, 2024, 4:27pm UTC](https://forum.inductiveautomation.com/t/a-way-to-wait-for-threads-to-complete-using-system-util-invokeasynchronous/95090/1 "2024-08-23T16:27:59Z")

</div>

an example splitting up system.tag.browse(). so if the loops executes 10 times and those threads are created, is there a way to wait for those threads to finish before continuing the code

global = system.tag.browse('Global')  
for path in global:  
----\> system.util.invokeAsynchronous(task, [path])

def task(path):  
----\> folder = system.tag.browse(str(path['fullPath']), {'recursive' : True} )  
----\>print 'thread done'

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 23, 2024, 4:50pm UTC](https://forum.inductiveautomation.com/t/a-way-to-wait-for-threads-to-complete-using-system-util-invokeasynchronous/95090/2 "2024-08-23T16:50:01Z")

</div>

`invokeAsynchronous()` returns the java `Thread` object. You can use java's `Thread.join()` method to wait on that thread. However, do not do this in any foreground script--that defeats the entire point of using a background thread (and will lock up your UI).

---

<div class="post-metadata">

**Author:** ![Gregory\_Novikov](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gregory_novikov/32/66734_2.png) [@Gregory\_Novikov](https://forum.inductiveautomation.com/u/Gregory_Novikov)\
**Post date:** [August 23, 2024, 5:11pm UTC](https://forum.inductiveautomation.com/t/a-way-to-wait-for-threads-to-complete-using-system-util-invokeasynchronous/95090/3 "2024-08-23T17:11:36Z")

</div>

Thanks for your response! It is not for a foreground script. I'll try it out.
