Fix bug #3139, "Mainwindow unresponsive due to a busy loop"