Quote Originally Posted by zvivered
This is what I'm trying to do in the button handler: The while (with sleep) causes the GUI to freeze.
Well, the code shows what you're currently doing, not what you want to happen. It's pretty obvious that calling Sleep() in your main thread freezes the UI.

Quote Originally Posted by zvivered
What should I do ?
As said above: What would you like to happen? It's still unclear how you expect your app to behave.