system.util.invokeLater issues

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]

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

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 my email list to get my newsletter…
Best,

Thanks Nick. That worked. Helpful article.