What’s the best way to deal with windows/dialogs that don’t fully close?
I have an ExtendScript script, which creates a dialog/window, where users can insert some arguments, etc.
Occasionally, when I click to run the script, the photoshop hangs up for a while (as usual), but the window does not fully close. More specifically, I don’t see the window elements, like buttons, texts, etc., anymore, I see only the window with a blank/white background and the title. See the screenshot below.

This blank dialog remains open all the time until I force close photoshop. The script execution continues and even finishes, but the window remains opened.
I suspect that this behaviour is due to the fact that close() doesn’t actually block, so the window may not be fully closed and cleaned once it returns.
What’s the best solution to solve this problem?
$.sleep(1000) does not seem to help and it's just seems wrong to use a sleep anyway. I suppose what we need is to just execute the heavy work until the window is fully closed.
I also tried to call app.refresh() before the heavy work, but I also don't know if this really solves the issue.
