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: