# Loading symbol while waiting for script to complete

**URL:** <https://forum.inductiveautomation.com/t/loading-symbol-while-waiting-for-script-to-complete/18649>\
**Category:** Ignition\
**Tags:** ignition79, database, scripting\
**Created:** [June 27, 2018, 6:54pm UTC](https://forum.inductiveautomation.com/t/loading-symbol-while-waiting-for-script-to-complete/18649 "2018-06-27T18:54:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Stuart](https://forum.inductiveautomation.com/u/Stuart)\
**Post date:** [June 27, 2018, 6:54pm UTC](https://forum.inductiveautomation.com/t/loading-symbol-while-waiting-for-script-to-complete/18649/1 "2018-06-27T18:54:23Z")

</div>

I have a button that when pressed, runs a script that in turn runs a bunch of SQL SELECT/UPDATE statements, and then closes the window. This takes a few seconds to run, and while it is running, the entire ignition window is unresponsive.

Is there a way to make a loading image or something? So that the user doesn’t feel that the client has crashed?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 27, 2018, 7:43pm UTC](https://forum.inductiveautomation.com/t/loading-symbol-while-waiting-for-script-to-complete/18649/2 "2018-06-27T19:43:29Z")

</div>

All scripting you do in the client runs (by default, and very deliberately) on the main Java Swing thread (also known as the Event Dispatch Thread). Any interaction with the GUI (ie, telling a component property to update, or animating a progress bar) _must_ happen on this thread, or deadlocks can result.

We offer two helper functions to aid in working around this restriction:  
[`system.util.invokeAsynchronous`](https://docs.inductiveautomation.com/display/DOC/system.util.invokeAsynchronous) which allows you to run a defined function on a background thread, and  
[`system.util.invokeLater`](https://docs.inductiveautomation.com/display/DOC/system.util.invokeLater), which allows that background thread to place operations _into the queue_ of the GUI thread to maintain thread-safety. So an extremely reductive example would be something like:

```auto
def setProgressBarState(target=event.source.parent.getComponent('Progress Bar')):
	target.value = target.value + 10

def mySlowFunction():
	# run some slow DB operation
	system.util.invokeLater(setProgressBarState)
	# run another slow DB operation
	system.util.invokeLater(setProgressBarState)
	# run another slow DB operation
	system.util.invokeLater(setProgressBarState)

system.util.invokeAsynchronous(mySlowFunction)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 19, 2021, 3:29pm UTC](https://forum.inductiveautomation.com/t/loading-symbol-while-waiting-for-script-to-complete/18649/3 "2021-11-19T15:29:50Z")

</div>

Split this topic on November 19, 2021, 3:29pm UTC

A post was split to a new topic: [Show progress bar during report loading](https://forum.inductiveautomation.com/t/show-progress-bar-during-report-loading/53293)
