Menu Close

My code that capture frames in burst mode in a GUI application, does not work in a console application

You are here:
< Back

In a console application, a waiting loop is needed just after StartPreview(), otherwise, if exiting the app after StartPreview(), this just terminates immediately the background thread, even before the 1st video frame as been received and processed.

The workaround consists to add a waiting loop just after invoking StartPreview():


bool CanClose = false;
VideoGrabber….
VideoGrabber….
VideoGrabber.StartPreview();
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (CanClose) { /// set CanClose = true to quit the waiting loop
break;
}
}
VideoGrabber.StopPreview();

(In a GUI application this waiting loop already exists, it’s the main thread’s loop that runs in the background and processes the Windows messages)

Last Updated On May 24, 2019