954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pause/Stop in C++

Hi,

I'm programming an application that records video samples of 5 seconds each. the recording takes place inside a loop.

I use MFC and DirectShow

The thing is, that the main thread must pause for 5 seconds while the sample is being recorded. in order to do that, I can use sleep or WaitForSingleObject but I still want to have the ability to click on the dialog's buttons (STOP for example...)

Is there any way to accomplish that without multithreading?

Hope this is understood. many thanks for your help!

omri374
Newbie Poster
4 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Hi, well I don't know DirectShow but I would think your application is already multithreading. You have your main thread and DirectShow is doing its things in another thread/threads. The problem is when you call WaitForSingleObject() you block the main thread until it is signaled from DirectShow and Windows does not have a change to process messages for the dialog. Perhaps you can call WaitForSingleObject() from a timer in the dialog and set the dwMilliseconds parameters to some short timeout, like 100ms. If WaitForSingleObject() returns WAIT_TIMEOUT you know DirectShow is still working. The dialog will then probably handle windows messages like WM_BUTTON_CLICK in the mean time.
Prefered way is probably running the dialog in the third thread. Then you have main thread, dialog thread and DirectShow thread.

hrafnk2009
Newbie Poster
4 posts since Sep 2009
Reputation Points: 10
Solved Threads: 2
 

Thanks!

Since I don't know much about Multithreading, I've decided to build it without the loops and with a timer. for now it's working alright, just that the code isn't very good lookin'...

omri374
Newbie Poster
4 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

Thanks!

Since I don't know much about Multithreading,

There's no better time than the present to learn. Write a simple console program that does nothing much more than create another thread and wait for it to finish. That is enough to show you how threads work -- its not really all that hard to do. CreateThread() parameters look complicated, but most of them can be set to NULL.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I used to work with threads in the past (Java programming). I guess it's pretty much similar.
thanks for the tip!

omri374
Newbie Poster
4 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: