use processEvents to prevent UI freeze