I started to learn c++ a while ago. I done a lot of console program with Visual Studio 2010 and now I want to make win32 programs. I read a lot of tutorial and I understand the basics now.
I made a button which call another function. The function is doing great everything working. But there are Sleep(x) in this function and the GUI isn’t responding while the Sleep doesn’t end. The function is done in 60 sec because there is a lot of Sleep in it but it is do everything what is should just do GUI isn’t responding this time.
I think I know the source of this problem. In my opinion the problem is Sleep totally pause the application (Windows say: not responding).
How can I make a Sleep/pause which doesn’t freeze the GUI? Is there a function or I must do it in a totally different way?
Thank you in advance!
Yes.
Why do you need to sleep in the first place? If the function is misbehaving, you can always run it in a background thread (but be aware that this adds quite a bit of complexity and difficulty). Normally, you shouldn’t need to sleep at all. If you do have to sleep, then make it a loop that spins until enough time passes, processing the events from the OS and calling
Sleep(0)which yields the timeslice.