Pause() function is screwing up control flow in my GUI

12 views (last 30 days)
Hi there!
I'm having some problems with the pause() function in a GUI that I've been working on. I realize that pause() has some known issues, so I'm hoping that someone will be familiar with the symptoms I'm seeing and know of a workaround. I'll try and describe my program as simply as possible, but I can add more detail if this is too vague.
The GUI has a "start" button whose callback includes a while loop that runs until the "stop" button is pressed. At the beginning of each loop iteration, there's a pause(0.02) to reduce the GUI's CPU load. During each iteration, the loop calls various functions to check on different things. If it doesn't like what it sees, it calls other functions, some of which include pause commands.
The problem I'm seeing is that the GUI doesn't seem to flow in a linear fashion, and I think that the pauses are to blame. For example, in the main while loop, there's an
if [function call 1] [function call 2, which includes a pause command] end
... and it seems that when function 1 returns true, function 1 still gets called many more times than function 2.
So - does this vague explanation ring any bells for anyone? Is there another function that I could use instead of pause() (supplemented by some "drawnow"s)? Or do I need to include a code sample to make this more comprehensible?
Thanks very much for your help.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 5 Oct 2011
"At the beginning of each loop iteration, there's a pause(0.02) to reduce the GUI's CPU load." This doesn't make sense to me. If you want to reduce the CPU load, you need to get rid of pause() so the time can be used to execute other code.
My experience on the need of using pause() in my GUI application is when there is a dialog, such as uigetfile() or msgbox(). After the user clicks the button, if there is intense calculation right after, the GUI usually freezes and cause problem. I found that adding a pause(0.1) solves the problem. drawnow() actually won't work as good as pause().
Is the pause() statement inside or outside the while-loop? If it's outside the while-loop, it sounds familiar to me as I assume the while-loop is CUP intense.
You'll probably need to show some code to let others get better idea.
  4 Comments
Ben
Ben on 5 Oct 2011
Yes, I can modify them. I already added output from each function to verify my suspicions. Unfortunately, commenting out all of the pause functions isn't really an option, but I can probably comment out some of them. I can probably disable the timer temporarily.
In the meantime, do you know of any functions that could substitute for pause? I do need that functionality in this program for it to work properly.
Fangjun Jiang
Fangjun Jiang on 5 Oct 2011
pause() just pauses the execution of the program. There is really no equivalent function for it. pause() can be used to replace drawnow() for updating GUI purpose because it implicitly called drawnow(). But it should not impact the programming flow. I suspect it is the timer object because pause() certainly interacts with the time.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!