TouchlessMgr.Dispose() hang

Jun 26, 2009 at 9:19 AM


When I try to dispose my TouchlessMgr instance, the app is freezing.

It hangs on "        g_pMediaControl->Stop();"  in "CameraMethods::StopCamera()" file "WebcamLib.cpp" line 381

I have revision 31008 of file (latest in svn).

My cam is a Microsoft VX-2000.

I think this can be due to not enough time between a previous dipose and a new instanciation of manager.


I have wrapped the lib into an ActiveX to use in a IE webpage.

I will try to search more further.

Jun 26, 2009 at 9:39 AM

Found : Deadlock


When calling IMediaControl.Stop(), there can be a deadlock if the UI thread is not responding.

Since I have a live view of the image (handle on Camera.OnImageCaptured event, get image, set picturebox image) and that I have to deal with InvokeRequired property, I have changed sync Invoke() calls to async calls with BeginInvoke(). And that solved my deadlock problem.

Link that helped me to understand :

Jun 26, 2009 at 12:19 PM

Great work,

I also could observe this deadlock from time to time in a plain win app, but could not explain to me why it happened.
I don't know if the BeginInvoke is ok to do and cleanly resolves the bug, but at least it helps :)

I could only observe the deadlock inside the debugger, but not when executing my app compiled in RELEASE mode and starting it outside the studio.

Jun 30, 2009 at 2:15 AM

Very nice. Is there anything more to it than changing OnImageCaptured.Invoke to OnImageCaptured.BeginInvoke? I'll work this into my next changeset.