LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

UI dies while Sleep() is executed

I am having problem with using the Sleep function. My User Interface dies (i.e. I am not able to do anything with my UI) when my code is executing the Sleep() function. As far as I think, it should not happen that way and we should be able to do other stuff with our user interface. Is there any solution to this problem?
 
 
0 Kudos
Message 1 of 2
(4,019 Views)

When you call sleep() from your main thread, it does just that, puts the thread to sleep for the period of time you specify.  During that period your UI is blocked because the thread it uses to respond to UI events is sleeping.  You have a lot of options:
You can put the routine that needs to sleep in another thread, this keeps the main UI thread from unblocked.
You can create a loop that uses the SDK function MsgWaitForMultipleObjectsEx() that allows your thread to sleep but to be awakened by some types of events. 
You can create your own equivalent to the sleep routine that simply loops while calling ProcessSystemEvents() for the period that you are trying to sleep.  ProcessSystemEvents() will unblock the UI Events.
You can design you system to be only event driven to avoid the need for a sleep routine.

If you can describe what you are trying to do we may be able to provide more input as to what may help.

0 Kudos
Message 2 of 2
(4,008 Views)