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!

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.

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'...

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.