# How to exchange date between GUI and a background thread?

**URL:** <https://forum.inductiveautomation.com/t/how-to-exchange-date-between-gui-and-a-background-thread/48051>\
**Category:** Ignition\
**Created:** [June 22, 2021, 9:20am UTC](https://forum.inductiveautomation.com/t/how-to-exchange-date-between-gui-and-a-background-thread/48051 "2021-06-22T09:20:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerald.Zhang](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Jerald.Zhang](https://forum.inductiveautomation.com/u/Jerald.Zhang)\
**Post date:** [June 22, 2021, 9:20am UTC](https://forum.inductiveautomation.com/t/how-to-exchange-date-between-gui-and-a-background-thread/48051/1 "2021-06-22T09:20:54Z")

</div>

I will start a global background task in a thread after client start, but how could I visit UI components in this thread?

---

<div class="post-metadata">

**Author:** ![Jerald.Zhang](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Jerald.Zhang](https://forum.inductiveautomation.com/u/Jerald.Zhang)\
**Post date:** [June 22, 2021, 9:22am UTC](https://forum.inductiveautomation.com/t/how-to-exchange-date-between-gui-and-a-background-thread/48051/2 "2021-06-22T09:22:43Z")

</div>

I now use:

1. Client tags
2. Window or control’s custom properties

Is this a right way?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 22, 2021, 12:02pm UTC](https://forum.inductiveautomation.com/t/how-to-exchange-date-between-gui-and-a-background-thread/48051/3 "2021-06-22T12:02:59Z")

</div>

This background task thread - are you running it on the gateway or via a background thread in the client? If via a background thread on the client using `system.util.invokeAsynchronous` then you necessarily must use `system.util.invokeLater` to affect the GUI, otherwise you risk freezing your GUI. The documentation has an example - [system.util.invokeAsynchronous - Ignition User Manual 7.8 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC/system.util.invokeAsynchronous)

---

<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:** [June 22, 2021, 1:11pm UTC](https://forum.inductiveautomation.com/t/how-to-exchange-date-between-gui-and-a-background-thread/48051/4 "2021-06-22T13:11:05Z")

</div>

> [@Jerald.Zhang](#):
>
> Is this a right way?

Client tags are a safe way to pass data between GUI (foreground) and an asynchronous thread (background). Directly accessing window objects and the components within them **is not safe**. You have to delegate to short functions in the foreground to make any changes and safely read values. This topic discusses the relevant techniques:

> [@Update GUI via Asynchronous thread](http://forum.inductiveautomation.com/t/update-gui-via-asynchronous-thread/9666):
>
> I’ve got a script I am experimenting with that can take a lot of time to execute, so I now use the system.util.invokeAsynchronous to run the script in a separate thread to keep the GUI from locking up. I am using the asynchronous thread to copy files from one place to another, and I would like to show the progress of the file copy with a progress bar. How would I go about this? I am importing a few python libraries to do this. import shutil def fileTransfer(): path = system.file.openFile() …

---

<div class="post-metadata">

**Author:** ![Jerald.Zhang](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Jerald.Zhang](https://forum.inductiveautomation.com/u/Jerald.Zhang)\
**Post date:** [June 23, 2021, 1:42am UTC](https://forum.inductiveautomation.com/t/how-to-exchange-date-between-gui-and-a-background-thread/48051/6 "2021-06-23T01:42:30Z")

</div>

Actually, Your answer makes me realized that my question is how to exchange data between thread and GUI. I will use client tags, Thanks for you suggest.
