Bug fix: move waiting onto the window's own thread