Desktop on second monitor is opened AFTER invokeLater

I want to open a maximized popup window on monitors 1 and 2 BEFORE I open a third-party application on monitor 1. We don’t want the users to click anywhere else on the Ignition application on monitor 1 or on other applications running on monitor 2 while the third-party application is running. I open a maximized desktop that I place on monitor 2 with a maximized popup window to cover the whole screen.
The maximized popup window opens as expected on monitor 1. However, the desktop on monitor 2 opens as expected only a few times, but most of the time it opens AFTER the third-party application is closed. Any help will be greatly appreciated. Below is my code; note that The “doStuff” function should be executed AFTER the openDesktop and openWindow lines, but it’s not always the case for openDesktop.

system.gui.openDesktop(screen=1, handle="Second Screen", windows=["Popups/01MaxPopup"])
system.nav.openWindow('Popups/02MaxPopup')

def doStuff():
    print “code to be executed AFTER the maximized popups are on screen”
    #do stuff
    #open third-party application
    #do stuff
    #close third-party application

system.util.invokeLater(doStuff)

Since your function is clearly using waits for external operations to happen, it is blocking the GUI thread. Ignition can’t perform UI operations like opening desktops and popups (or anything else) while your “#do stuff” is hogging the foreground thread.

In general, sleeping or waiting in the UI thread is forbidden. { It’s usually a bad idea in other contexts too. }

Ignition’s client is an event-driven system (because Java Swing is event driven). Events need to execute to completion in a fraction of a second. Any waiting needed must be implemented with timer events and/or timer components and/or asynchronous threads.

If you choose that last, see this topic for the restrictions on what those can do:

1 Like

It seems like openDesktop sometimes takes too much time because it has to create a new desktop each time, but just maximizing it doesn’t, so I moved openDesktop to the Client Startup and minimized it. I just maximize the second desktop before calling the “doStuff” function, and now it is working as expected. I tested it on 12 computers with hundreds of orders. Another solution would be to move the function to the window on the second desktop, but it would be more work for me because I have multiple instances where I call the third-party application.
Here is the new code:

project.inputControl.max2ndDesktop() #Desktop already exists, just maximize it. system.nav.openWindow('Popups/02MaxPopup')

def doStuff():
    print “code to be executed AFTER the maximized popups are on screen”
    #do stuff
    #open third-party application
    #do stuff
    #close third-party application

system.util.invokeLater(doStuff)
project.inputControl.min2ndDesktop() #Don’t close it, just minimize it

I appreciate your response. The popup and the desktop don’t have code; I just use them to cover the screens while the third-party application is open. Now the logic is: 1) Maximize popup and desktop2, 2)Use invokeLater to call “doStuff”, and 3)Minimize popup and desktop2.
The solution works, but I will make sure to let you know if I have issues in the future.