# Thread Cleanup and the Paintable Canvas

**URL:** <https://forum.inductiveautomation.com/t/thread-cleanup-and-the-paintable-canvas/7001>\
**Category:** Ignition\
**Created:** [August 7, 2013, 11:34pm UTC](https://forum.inductiveautomation.com/t/thread-cleanup-and-the-paintable-canvas/7001 "2013-08-07T23:34:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [August 7, 2013, 11:34pm UTC](https://forum.inductiveautomation.com/t/thread-cleanup-and-the-paintable-canvas/7001/1 "2013-08-07T23:34:13Z")

</div>

I wrote a rather lengthy initialization script, called from my Client Startup event. I pushed the bulk of the work onto a background thread with invokeAsynchronous, and updated a splash screen with invokeLater. Once I was certain that all of my necessary initialization had finished, I opened my annunciator window, and closed my splash screen.

The annunciator window contains a large, paintable canvas that previously drew icons to represent physical stations. It had been working quite well for months. Unfortunately, reorganizing my code seems to have broken the repaint event, even though I haven’t altered it. It takes a few extra seconds to draw some text and lines, then it draws a single station, which it happily updates. It will not draw the other stations.

Could opening those various background threads have harmed the performance of the paintable canvas? According to my traces, all of the tasks that I put on the background threads have finished. Is there some sort of final cleanup I need to do to destroy those threads?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [January 9, 2014, 6:18pm UTC](https://forum.inductiveautomation.com/t/thread-cleanup-and-the-paintable-canvas/7001/2 "2014-01-09T18:18:36Z")

</div>

No, there’s not anything you need to do to clean up the threads. Once your method completes, the thread started by invoke asynchronous dies.

It must be something else going on inside the painting code. I’d try adding print statements that compare the time between various parts to try and narrow down on what inside the painting code is taking a long time.

Also realize that while the paint event is running, you shouldn’t see anything updating on the screen. What I mean is, you should only see something visually happening after _all_ the painting code has finished running. Is this consistent with what you’re observing?

---

<div class="post-metadata">

**Author:** ![lisawas](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@lisawas](https://forum.inductiveautomation.com/u/lisawas)\
**Post date:** [January 23, 2014, 5:12pm UTC](https://forum.inductiveautomation.com/t/thread-cleanup-and-the-paintable-canvas/7001/3 "2014-01-23T17:12:29Z")

</div>

I found the culprit…it was a stupid coding error…I lost an indent. Thank you.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [January 23, 2014, 5:57pm UTC](https://forum.inductiveautomation.com/t/thread-cleanup-and-the-paintable-canvas/7001/4 "2014-01-23T17:57:13Z")

</div>

Glad you found it. Darn those pesky indents!

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [January 23, 2014, 6:10pm UTC](https://forum.inductiveautomation.com/t/thread-cleanup-and-the-paintable-canvas/7001/5 "2014-01-23T18:10:58Z")

</div>

Another case for improving the script editor so that it shows what code is in a block and what isn’t… I’m just saying! 😉
