Blocking the message thread and periodically forcing it to run to do synchronous paining is an old-school technique that is very dangerous, and is actually impossible on some newer platforms like Android. Don't do it!
The way to do this kind of thing properly is just to do your work on a thread and send messages to your GUI to tell it to repaint when necessary.