Prevent the application from freezing after dispose() is called in certain circumstances