Use a monitor class with a global instance and which your code is updated (I am starting, I am working, I am at xxx%, I am finished).
Then the monitor can decide to show the dialog and keep it up to date. Later, you can simply replace the dialog with a progress bar in the status bar, for example. Use the monitor interface (methods: start (), update (), end (), error (), isAborted ()) so that you can replace it with something else.
You can expand the monitor to 500 ms after starting (), if there is an end (), and not show a dialog in this case, etc.
This is how Eclipse does this and it works well.
source share