"while loop" in a thread
In my MFC, .NET application I want a video animation to continously run
in a separate window, while operations in the main window are allowed
to be performed. The video animation runs continously, grabbing frames
from a cicrular buffer, until a message from the main window terminates
(or changes) it.
I create the animation window from AfxBeginThread(). Inside the
animation window class I have a while loop that updates the frames of
the animation while a global flag is true.
I found that the while loop in the thread, instead of displaying the
animation, eats up all the resources and hangs the whole application
This forces me to use a hard kill to stop the program. This, in turn,
causes blue screens, since connection with the video hardware that
writes the animation frames into a circular buffer is not closed with
the hard kill. (As Alexander pointed out, the driver of the harware
does not detect real time cancelations... but this is the only hardware
I can use). It gets pretty gross: I got some .h files corrupted this
way.
How can I make the thread do smth continously w/o eating up all the
resourses?
//CAPPDlg.cpp
void initiateAnimation() {
anim_thread_running = true;//global flag;
pAnimation_thread =
(CAnimation_thread*)AfxBeginThread(RUNTIME_CLASS(CAnimation_thread));
}
//CAnimationwindow.cpp
OnInitDialog() {
while (anim_thread_running) {
UpdateAnimationBitmap();
}