# system.util.invokeLater issues

**URL:** <https://forum.inductiveautomation.com/t/system-util-invokelater-issues/12813>\
**Category:** Ignition\
**Created:** [March 20, 2017, 2:32am UTC](https://forum.inductiveautomation.com/t/system-util-invokelater-issues/12813 "2017-03-20T02:32:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kstofcho](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@Kstofcho](https://forum.inductiveautomation.com/u/Kstofcho)\
**Post date:** [March 20, 2017, 2:32am UTC](https://forum.inductiveautomation.com/t/system-util-invokelater-issues/12813/1 "2017-03-20T02:32:27Z")

</div>

I am attempting to use the invokeLater function to open a window, run some code (which often takes 5-15sec due to utilizing a web API) then close that opened window. My goal is to create a semi-transparent lock screen with a loading bar so that user knows that the system is processing. The following code simply opens and closes the window instantly rather than waiting for the “move” script to fully process before closing the window. Why would this happen and how can I go about fixing it? My understanding was that with the invokeLater script openLock then move then closeLock should execute in that order one after the other.

[code]def save():  
def openLock():  
system.nav.openWindow(‘Navigation/Lock screen’)   
def closeLock():  
system.nav.closeWindow(‘Navigation/Lock screen’)   
def move():  
def nothing():  
print ‘nothing’  
system.util.invokeLater(nothing, 10000)

```
system.util.invokeLater(openLock)
system.util.invokeLater(move)
system.util.invokeLater(closeLock)

```

system.util.invokeAsynchronous(save)  
[/code]

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [March 20, 2017, 5:00am UTC](https://forum.inductiveautomation.com/t/system-util-invokelater-issues/12813/2 "2017-03-20T05:00:21Z")

</div>

Hi Kstofcho,

The system.util.invokeLater function returns immediately. It doesn’t wait for anything. The second delay argument just schedules the function to be executed on the event dispatch thread at the delay time you provided.

I suggest reading my article [Understanding Threading, system.util.invokeAsynchronous in Ignition](http://nickmudge.info/post/understanding-threading-system.util.invokelater-and-system.util.invokeasynchronous-in-Ignition)

Here is how you want to write this code:`from java.lang import Thread
def save():
	def openLock():
		system.nav.openWindow('Navigation/Lock screen')	
	def closeLock():
		system.nav.closeWindow('Navigation/Lock screen')
	#Open the window
	system.util.invokeLater(openLock)
	#Execute your long running code here that doesn't touch the GUI
	#Using Thread.sleep to simulate long running code
	#sleeping for 5 seconds
	Thread.sleep(5000)
	#Long running code is done so we close the window
	system.util.invokeLater(closeLock)
system.util.invokeAsynchronous(save)`Please [join](http://www.perfectabstractions.com/mailing-list.html) my email list to get my newsletter…  
Best,

---

<div class="post-metadata">

**Author:** ![Kstofcho](https://avatars.discourse-cdn.com/v4/letter/k/a9a28c/32.png) [@Kstofcho](https://forum.inductiveautomation.com/u/Kstofcho)\
**Post date:** [March 22, 2017, 6:15pm UTC](https://forum.inductiveautomation.com/t/system-util-invokelater-issues/12813/3 "2017-03-22T18:15:31Z")

</div>

Thanks Nick. That worked. Helpful article.
