Fixing a multithreading lag when closing the app