Check if a thread is still running
-
Hello, if I use AfxBeginThread() function to start a thread, how do I check if it's still running or has already exited?
Normally you shouldn't care. What exactly is it that you are attempting to do?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Normally you shouldn't care. What exactly is it that you are attempting to do?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
I have a thread that plays a sequence of images. In the CDocument I handle controls to pause/play using events and boolean variables. I chose start the thread inside play() function. The way I handle pause() I don't care if the thread is there or not. However if the user presses play again, I don't want to start another thread, I want to continue the previous one. I have the option of making a thread that runs for the life of the CDocument...but wouldn't that be wasteful when it sits there and waits on pause forever after a single play.
-
Hello, if I use AfxBeginThread() function to start a thread, how do I check if it's still running or has already exited?
AfxBeginThread returns the pointer of the created thread CWinThread. Using
BOOL GetExitCodeThread( HANDLE hThread, LPDWORD lpExitCode);
you can get the status of this thread (STILL_ACTIVE if it's not terminated). Marc Soleda ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits. -
I have a thread that plays a sequence of images. In the CDocument I handle controls to pause/play using events and boolean variables. I chose start the thread inside play() function. The way I handle pause() I don't care if the thread is there or not. However if the user presses play again, I don't want to start another thread, I want to continue the previous one. I have the option of making a thread that runs for the life of the CDocument...but wouldn't that be wasteful when it sits there and waits on pause forever after a single play.
-
I have a thread that plays a sequence of images. In the CDocument I handle controls to pause/play using events and boolean variables. I chose start the thread inside play() function. The way I handle pause() I don't care if the thread is there or not. However if the user presses play again, I don't want to start another thread, I want to continue the previous one. I have the option of making a thread that runs for the life of the CDocument...but wouldn't that be wasteful when it sits there and waits on pause forever after a single play.
See here for details on how to properly pause and stop threads.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
See here for details on how to properly pause and stop threads.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Yes, that's what I use. Taken from the site:
// thread body: while(running) { /* loop */ if(paused) switch(::WaitForSingleObject(event, time)) { case WAIT_OBJECT_0: break; case WAIT_TIMEOUT: continue; } // rest of thread } /* loop */
except instead of while(running), I have a for loop from 0 to numImages. -
I have a thread that plays a sequence of images. In the CDocument I handle controls to pause/play using events and boolean variables. I chose start the thread inside play() function. The way I handle pause() I don't care if the thread is there or not. However if the user presses play again, I don't want to start another thread, I want to continue the previous one. I have the option of making a thread that runs for the life of the CDocument...but wouldn't that be wasteful when it sits there and waits on pause forever after a single play.
Budric B. wrote: but wouldn't that be wasteful when it sits there and waits on pause forever after a single play. Not neccessarily. Or at least I wouldn't think so if you're using WaitForSingleObject() to do the "waiting" and not a busy wait while loop. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!
-
Budric B. wrote: but wouldn't that be wasteful when it sits there and waits on pause forever after a single play. Not neccessarily. Or at least I wouldn't think so if you're using WaitForSingleObject() to do the "waiting" and not a busy wait while loop. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!
Jim Crafton wrote: ...if you're using WaitForSingleObject() to do the "waiting" and not a busy wait while loop. Correct.
WaitForSingleObject()
uses no CPU time while waiting for the object state to become signaled or the time-out interval to elapse.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown