Re: UI Freeze Problem
rahulthathoo wrote:
My problem is that the cpu usage becomes 100% - this is because i need
to refresh the dialog after a sleep of 10 miliseconds. but the problem
is that the sleep makes the UI freeze. I thought a workaround would be
using threads. but even after using threads and events the problem
persists - the UI still freezes. Please tell me what is going wrong
here. Here is the code listing:
Your UI has to be message-driven, not loop-driven. Any "while(TRUE)"
loop in the main thread will freeze the UI, and any "while(TRUE)" loop
in a secondary thread will cause 100% CPU usage. Eliminate these loops!
To keep the UI alive you must (MUST!) structure OnPaint so it paints
one time and then returns. (It returns to the message loop to check for
any user input.)
You may not be able to get 10 msec repaint rate. But the best you can
do would be to set up a timer and call the window's Invalidate in
response to each timer message (WM_TIMER). The Invalidate call will
generate a new OnPaint after all user input is processed.
If the resulting performance is inadequate for you then you should
consider throwing out MFC and studying a game programming book. In MFC
you have to work with the MFC message loop; in game programming you
write your own message loop and paint when you want to.)
--
Scott McPhillips [VC++ MVP]