This project is read-only.

RunWorker() not terminating?


When Stop() is called on the CapDevice object:
public void Stop()
            // Check if the capture device is even running
            if (IsRunning)
                // Yes, stop via the event
                // Abort the thread

                if (_worker != null)
                    // Join
                    // Release
Everything seems to work... _Stopsignal is set and the _worker Thread status goes to AbortRequested. Also, the Runworker() will move to the final instructions being: _control.StopWhenReady(); Which is the expected behavior.
However, after this the Thread.Join() waiting state inside Stop() never finishes if I don't put the 5000 ms timeout (see above). This means that the _worker Thread never actually finishes.
I therefore suspect that there is an issue with the implementation of the hardware interaction or something else that prevents proper execution of _control.StopWhenReady() or even _control.Stop().
Could this be confirmed or am I completely missing something here.
After _worker.Abort() I expect the _worker Thread to actually fully stop, but it never does...


KrisJ wrote Mar 23, 2009 at 3:45 PM

Could it be that this kind of stuff has something to do with the _control.stop() or _control.StopWhenReady() possibly not working as advertised?

Especially the last post about IVideoWindow seems interesting.

KrisJ wrote Mar 24, 2009 at 8:56 PM

I now found out there was no error within the code handling the camera.

The calls related to the worker thread were completely in the wrong order...

Thread.Abort() was called too early. Therefore the while loop in RunWorker() did not exit yet and the thread was aborted before _control.StopWhenReady() could be called...

I have updated code to solve things. If the original author contacts me I could have the new code added to the project.

plexorama wrote Jun 4, 2009 at 2:02 AM

adding the following code in the finally{}-branch within RunWorker() before the "graph = null;"-line solves an issue when reusing/restarting the CapDevice:


graph.Disconnect(sourceObject.GetPin(PinDirection.Output, 0));
graph.Disconnect(grabberObject.GetPin(PinDirection.Input, 0));



jmaldonadom wrote Mar 16, 2010 at 6:07 PM

Hi KrisJ, You could post your code? a couple of days I've been struggling with this problem ...

wrote Feb 14, 2013 at 8:20 PM