-
November 16th, 2012, 06:29 AM
#1
Terminate a thread
Hi,
I have a thread with a while(1) loop in it. When the user push the stop button I would like that thread to end.
I thought about creating a bool and checking its value periodically in the thread and when I push the stop
button I change the value of the bool for that the thread breaks out of the loop and finishes.
Is it the best way to go about it, that's how professional programmers do it also?
-
November 16th, 2012, 08:51 AM
#2
Re: Terminate a thread
if you are attempting to paint the overlay yourself via a timer or update loop: this cannot be done with a picture control. that would only work if the picture control gives you an actual indication as to when the image was updated (which it doesn't).
If the painting stops, I'm going to assume you're not releasing some GDI resources, and after a while you're exhausing the GDI resources for your application. Creating another font, pen, brush... simply fails because no more can be made. THis is a resource leak and you'll need to fix it.
The only way I know of that this is possible with a picture control is to use a tranparent layered window approach.
Have a look at the WS_EX_LAYERED style on MSDN. This is used in combination with UpdateLayeredWindow().
Do note that depending on your videocard and the OS used, this could have a serious impact on CPU usage and/or framerate.
-
November 16th, 2012, 08:53 AM
#3
Re: Terminate a thread
Alternatively, use a more advanced control to playback video which does have a means to allow you to paint overlays.
-
November 16th, 2012, 09:19 AM
#4
Re: Terminate a thread
Thank you OReubens, fortunately there is no painting involved only updating of a listbox.
So can I assume that my method is the right one for what Im doing?
-
November 17th, 2012, 02:31 AM
#5
Re: Terminate a thread
Your method is acceptable under condition that the boolean variable access is thread safe. Though I always prefer to communicate with threads by means of signalling objects, events for example.
Best regards,
Igor
-
November 17th, 2012, 12:58 PM
#6
Re: Terminate a thread
Thank you Igor, that's what I wanted to know.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|