# Repaintable canvas to show Cognex camera image

**URL:** <https://forum.inductiveautomation.com/t/repaintable-canvas-to-show-cognex-camera-image/48820>\
**Category:** Ignition\
**Created:** [July 14, 2021, 11:46am UTC](https://forum.inductiveautomation.com/t/repaintable-canvas-to-show-cognex-camera-image/48820 "2021-07-14T11:46:37Z")\
**Posts on this page:** 1\
**Showing post:** 7

<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:** [July 14, 2021, 1:23pm UTC](https://forum.inductiveautomation.com/t/repaintable-canvas-to-show-cognex-camera-image/48820/7 "2021-07-14T13:23:03Z")

</div>

An async script is any script function that is executed via [system.util.invokeAsynchronous()](https://docs.inductiveautomation.com/display/DOC81/system.util.invokeAsynchronous). I generally prefer to place such functions in project script modules, but they can also be defined in-line (nested) in another script. Java Swing (the base for Vision) is **single-threaded**. Component events in Vision are really Java Swing events and run on the Swing GUI thread. Running time-consuming code in a component event _ **freezes the GUI** _. That would include code that sleeps or waits on the network or the filesystem. Don't do it.

However, running in a background thread has some limitations, too. Since Swing is single-threaded, it is full of operations on components that are **unlocked**. You can get away with manipulating components from a background thread for a long time, but eventually you'll corrupt a component and _ **crash** _ Vision. Not just locked up. _ **Dead.** _ Passing data back to Swing requires using [system.util.invokeLater()](https://docs.inductiveautomation.com/display/DOC81/system.util.invokeLater).

See these topics for many details:

> [@Update progress bar from within a script](http://forum.inductiveautomation.com/t/update-progress-bar-from-within-a-script/21995/3):
>
> 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 t…

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

---

_[View the full topic](https://forum.inductiveautomation.com/t/repaintable-canvas-to-show-cognex-camera-image/48820)._
