In my macOS app (objC), the user can trigger tasks that can take some time, like importing files into a database. These tasks do not run on the main thread because they spawn a window (sheet) to show the task's progress and to allow cancelling the task. The window is modal because I don't want the user to do anything during these task (like quitting the app, or undoing stuff), except cancelling the task. At the same time, I don't want the progress window to show immediately, as the task may be quite short (< 1sec). Showing a modal sheet for less than 1 sec would be distracting.
So I'm currently showing the progress window after a delay of 1 second (or don't show it at all if the task took less time). But during this 1 second, nothing prevents the user from doing silly stuff, like deleting a folder in which items are being imported. [By "Folder", I don't mean folders of the Finder, just containers that my app manages].
I could prevent user actions on a case-by-case basis by overriding every method that I don't want to be executed during these tasks (these method would check if some task is ongoing) or I could adapt the code to accommodate the consequences of user actions (e.g. what to do if the folder in which the file are being imported has been deleted). I'am already doing the latter to some extent, but it is difficult to imagine every possible user action with adverse effet. So as a safety measure, I'd like to prevent any user action in my app before the progress window shows.
Some my question is: How do I prevent my app from responding to user actions in an "invisible" manner without blocking the main thread?