fixed a bug not to block while the application is about to close.