# \[SOLVED\] Update HMI Screen while script is running

**URL:** <https://forum.inductiveautomation.com/t/solved-update-hmi-screen-while-script-is-running/32857>\
**Category:** Ignition\
**Created:** [March 5, 2020, 9:24pm UTC](https://forum.inductiveautomation.com/t/solved-update-hmi-screen-while-script-is-running/32857 "2020-03-05T21:24:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [March 5, 2020, 9:24pm UTC](https://forum.inductiveautomation.com/t/solved-update-hmi-screen-while-script-is-running/32857/1 "2020-03-05T21:24:24Z")

</div>

Good afternoon,

I have a script that runs when the user scans an RFID. What I have noticed is the screen will not update until the script has finished running. So if I change some text on the screen to “SCRIPT RUNNING” at the beginning of my script and “SCRIPT STOPPED” at the end of my script I will not see any change on the screen until the script has finished running at which point I might briefly see “SCRIPT RUNNING” which immediately changes back to “SCRIPT STOPPED”.

Any clue on how to make the “SCRIPT RUNNING” appear as soon as I write that value in the script?

---

<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:** [March 5, 2020, 9:32pm UTC](https://forum.inductiveautomation.com/t/solved-update-hmi-screen-while-script-is-running/32857/2 "2020-03-05T21:32:34Z")

</div>

That is what system.util.invokeAsynchronous() is for. Event scripts should never run for more than a tiny fraction of a second, as the java Swing user interface is single-threaded. 100 milliseconds is a good rule of thumb. Anything longer should be put on a background thread, which can then post its results using system.util.invokeLater(). Note, background threads may not interact with windows, components, or their properties _ **at all** _.

There are numerous discussions of invokeAsynchronous and invokeLater in this forum’s archives.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [March 6, 2020, 2:09pm UTC](https://forum.inductiveautomation.com/t/solved-update-hmi-screen-while-script-is-running/32857/3 "2020-03-06T14:09:05Z")

</div>

> That is what system.util.invokeAsynchronous() is for. Event scripts should never run for more than a tiny fraction of a second, as the java Swing user interface is single-threaded. 100 milliseconds is a good rule of thumb. Anything longer should be put on a background thread, which can then post its results using system.util.invokeLater(). Note, background threads may not interact with windows, components, or their properties _ **at all** _ .

This is very interesting news to me. I have a password text box on my screen. The user scans an RFID tag on an RFID reader and a 'propertyChange' event is triggered. I do some checking to ensure this propertyChange is the one I want and then execute the following:

```
system.util.invokeLater(evaluateRFID, 2500)

```

And within the same propertyChange script I go off to the evaluateRFID definition. This definition reads/writes to tags and does some SQL queries but it doesn't appear to interact with the window, components, or their properties. Could I, or should I, move evaluateRFID to a project script location?

---

<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:** [March 6, 2020, 3:38pm UTC](https://forum.inductiveautomation.com/t/solved-update-hmi-screen-while-script-is-running/32857/4 "2020-03-06T15:38:02Z")

</div>

Well, don't confuse background with project script. A project script can be used in both foreground (events) and background. Script modules are a way to avoid repeating oneself in code--not a control over how they are executed. Based on your description, I would certainly move that task to a function run asynchronously, and a project script is a good place to put such a function.

This sort of stuff is enough of a minefield that I created a number of wrapper functions to help, to be installed as a shared or global script. You might find this topic helpful:

> [@Update GUI via Asynchronous thread](http://forum.inductiveautomation.com/t/update-gui-via-asynchronous-thread/9666/3):
>
> Since this sort of thing pops up often, I created a set of wrappers that simplify this stuff, and allows you to directly use functions in your script modules. The wrappers take care of stuffing the arguments you supply into a temporary fuction’s default argument. For your case, try assignLater(). Nick’s example becomes: # In a script module in your project: import shutil def fileTransfer(label): path = system.file.openFile() newPath = "F:\NewFolder" shutil.copy2(path, newPath) sh…

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [March 6, 2020, 7:16pm UTC](https://forum.inductiveautomation.com/t/solved-update-hmi-screen-while-script-is-running/32857/5 "2020-03-06T19:16:32Z")

</div>

Just wanted you to know these wrappers saved my life. They are awesome!
