# Update progress bar from within a script

**URL:** <https://forum.inductiveautomation.com/t/update-progress-bar-from-within-a-script/21995>\
**Category:** Ignition\
**Created:** [January 19, 2019, 4:45pm UTC](https://forum.inductiveautomation.com/t/update-progress-bar-from-within-a-script/21995 "2019-01-19T16:45:51Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [January 19, 2019, 6:24pm UTC](https://forum.inductiveautomation.com/t/update-progress-bar-from-within-a-script/21995/3 "2019-01-19T18:24:38Z")

</div>

Event scripts run in the foreground. Painting the UI runs in the foreground, so it can't happen until your script finishes. You need to wrap up your long-running operation into a function, and then run that with invokeAsynchronous. That function can send updates back to the foreground with invokeLater.

You _must_ not _ **ever** _ assign to component properties or call component methods from an asynchronous (background) function. You can really scramble Swing and/or deadlock it. Take a look at this thread for a discussion of possibilities:

> [@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() …

Naturally, I recommend using the `callAsync()` and `assignLater()` functions from my `later.py` script module.

---

_[View the full topic](https://forum.inductiveautomation.com/t/update-progress-bar-from-within-a-script/21995)._
