And while at it, use a switch clause to make the state machine structure clearer.
Data loading in a second thread with progress bar in main thread