# Killing/Interrupting a Thread started by system.util.invokeAsynchronous

**URL:** <https://forum.inductiveautomation.com/t/killing-interrupting-a-thread-started-by-system-util-invokeasynchronous/76492>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [July 17, 2023, 10:30pm UTC](https://forum.inductiveautomation.com/t/killing-interrupting-a-thread-started-by-system-util-invokeasynchronous/76492 "2023-07-17T22:30:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyler.robertson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tyler.robertson/32/18299_2.png) [@tyler.robertson](https://forum.inductiveautomation.com/u/tyler.robertson)\
**Post date:** [July 17, 2023, 10:30pm UTC](https://forum.inductiveautomation.com/t/killing-interrupting-a-thread-started-by-system-util-invokeasynchronous/76492/1 "2023-07-17T22:30:10Z")

</div>

Hello,

**system.util.invokeAsynchronous** returns the Thread it starts which is great, but I'm missing something in how I might be able to store that Thread object, or reference - so I can stop the Thread later on.

ex: I have a local TCP connection being established from a Vision client to another application on a device. Occasionally that application stops sending data unless a new connection is made (ie: it times out on its end without closing the connection).. I would like to then initiate a new connection... without blocking the HMI, so I've needed to use **system.util.invokeAsynchronous** - however anytime I start a new connection, it starts in a new thread and there's still that original connection.

If I'm starting a thread based on a property or button event, how can I later on reference that thread?

Thanks!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 17, 2023, 11:00pm UTC](https://forum.inductiveautomation.com/t/killing-interrupting-a-thread-started-by-system-util-invokeasynchronous/76492/2 "2023-07-17T23:00:43Z")

</div>

The real answer here is that the thread should manage it's own lifecycle. You shouldn't kill threads.

> [@Ignition Memory increasing after Scripting Restart](https://forum.inductiveautomation.com/t/ignition-memory-increasing-after-scripting-restart/66799/11):
>
> It isn’t safe to kill threads. Threads can and should be designed to be interruptible (checking for interrupt status and/or exceptions for graceful exit). If you didn’t do that, interrupt() may not work. If not, you will have to restart the gateway. Start here: Some other search results: [https://forum.inductiveautomation.com/search?q=kill%20invokeAsynchronous](https://forum.inductiveautomation.com/search?q=kill%20invokeAsynchronous)[https://forum.inductiveautomation.com/search?q=persistent%20thread%20leak](https://forum.inductiveautomation.com/search?q=persistent%20thread%20leak)

---

<div class="post-metadata">

**Author:** ![tyler.robertson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tyler.robertson/32/18299_2.png) [@tyler.robertson](https://forum.inductiveautomation.com/u/tyler.robertson)\
**Post date:** [July 18, 2023, 9:02pm UTC](https://forum.inductiveautomation.com/t/killing-interrupting-a-thread-started-by-system-util-invokeasynchronous/76492/3 "2023-07-18T21:02:10Z")

</div>

That's a really good point and probably the crux of my problem - if there's a problem with the connection and I need to start anew, I can interupt, and note if possible

Thanks for the sanity check
