Sleep in Button Click
-
In my MFC app, I needed to sleep (delay the thread) for 3 seconds. But when I added sleep in BtnClick afx function, it just didn't work. I did a work around be using 3 seconds Timmer. But How to avoid such situations in future??? Thanks for reply in advance :-) -- CHEERS!!!!
-
In my MFC app, I needed to sleep (delay the thread) for 3 seconds. But when I added sleep in BtnClick afx function, it just didn't work. I did a work around be using 3 seconds Timmer. But How to avoid such situations in future??? Thanks for reply in advance :-) -- CHEERS!!!!
How did you conclude that the sleep function does not work? Did you see any frozen UI for 3 seconds?
You talk about Being HUMAN. I have it in my name AnsHUMAN
-
How did you conclude that the sleep function does not work? Did you see any frozen UI for 3 seconds?
You talk about Being HUMAN. I have it in my name AnsHUMAN
I am creating a Custom Media Player using Windows Media Player COM objects. When I play the mp3, it takes near about 3 sec to load the files(and necessary dlls). Before that, the duration of the mp3 is not reflected in the properties. Yes there was a frozen UI. But rest of the thread continued and I was unable to record the duration. Thanks for replying :-)
-
I am creating a Custom Media Player using Windows Media Player COM objects. When I play the mp3, it takes near about 3 sec to load the files(and necessary dlls). Before that, the duration of the mp3 is not reflected in the properties. Yes there was a frozen UI. But rest of the thread continued and I was unable to record the duration. Thanks for replying :-)
Are you using another thread to read/load the necessary files or the dll's or you are doing it in the main thread?
You talk about Being HUMAN. I have it in my name AnsHUMAN
-
Are you using another thread to read/load the necessary files or the dll's or you are doing it in the main thread?
You talk about Being HUMAN. I have it in my name AnsHUMAN
I am loading it in the main thread itself...
-
I am loading it in the main thread itself...
Then obviously your code for loading the dll's etc will not run during the freeze/sleep as the main thread is sleeping. You should load all dll's in a separate thread and once you are sure that they are loaded, notify the main thread to resume. May be you could have a better idea as well.
You talk about Being HUMAN. I have it in my name AnsHUMAN
-
I am creating a Custom Media Player using Windows Media Player COM objects. When I play the mp3, it takes near about 3 sec to load the files(and necessary dlls). Before that, the duration of the mp3 is not reflected in the properties. Yes there was a frozen UI. But rest of the thread continued and I was unable to record the duration. Thanks for replying :-)
UI frozen=Sleep worked... like it was suggested, create a loading thread and have that thread message back to the original thread when he's done. Using Sleep() in this manner is not acceptable, you're freezing the user interface on purpose, many do it on accident, but on purpose!?
-
Then obviously your code for loading the dll's etc will not run during the freeze/sleep as the main thread is sleeping. You should load all dll's in a separate thread and once you are sure that they are loaded, notify the main thread to resume. May be you could have a better idea as well.
You talk about Being HUMAN. I have it in my name AnsHUMAN
great feedback for OP :thumbsup:
-
UI frozen=Sleep worked... like it was suggested, create a loading thread and have that thread message back to the original thread when he's done. Using Sleep() in this manner is not acceptable, you're freezing the user interface on purpose, many do it on accident, but on purpose!?
So does that means using Sleep() (in main thread) in mfc in condemned??? I never realized that. I think a lighter way was what I did (activated a timer and went to sleep there). Thread is also a good option. Thanks for the reply.
-
So does that means using Sleep() (in main thread) in mfc in condemned??? I never realized that. I think a lighter way was what I did (activated a timer and went to sleep there). Thread is also a good option. Thanks for the reply.
It's condemned to use Sleep()(for this length of time) in UI thread(its common for people to separate the UI from the rest of the code).