magician-david / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

calling Stop or WaitForStop on a VideoCaptureDevice can hang indefinately #276

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Call Stop or WaitForStop on a VideoCaptureDevice
2. Device does not respond (example - unplugged / driver issue)
3. Thread hangs indefinitely and won't exit - task manager shutdown only option 
and sometimes even the task manager can't quit it.

What is the expected output? What do you see instead?
should exit after timeout

What version of the product are you using?
2.2.3

Please provide any additional information below.

calling thread.Join() in WaitForStop( ) in  VideoCaptureDevice.cs doesn't 
provide a timeout - should provide a timeout and handle aborting the thread if 
it's not responding. The WaitForStop() public function should also ensure that 
the stopEvent has been set.

Original issue reported on code.google.com by ad...@activeunlimited.com on 7 Jan 2012 at 1:04

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
in this case I use System.Threading.Timer like that:

  dev.Start();  // start capture device
  tm = new Timer(new TimerCallback(tm_Tick), dev, waitLimit_AForge, Timeout.Infinite);   // start timer
  dev.WaitForStop();
  tm.Dispose();            // stop timer

Method tm_Tick do: dev.SignalToStop(); 

I have timeout 10sec 

Original comment by mtester...@gmail.com on 17 Jan 2012 at 9:16

GoogleCodeExporter commented 8 years ago
Stop() method should abort thread.

Are you sure you don't have any dead locks in your UI? Sometimes this is a case 
for issues like yours.

Check that you don't have something like this: from UI you select Stop -> 
camera thread tries to stop -> before exiting, the camera thread fires 
PlayingFinished event -> your PlayingFinished event handler tries to update UI 
-> since UI is busy by calling Stop you get a dead lock.

Simple pause your application when running in debug mode and check what each 
thread does and check callstacks.

Original comment by andrew.k...@gmail.com on 25 Jan 2012 at 9:44

GoogleCodeExporter commented 8 years ago
Thanks, Andrew.

I had the same issues and your solution was spot on: UI deadlock ...

BTW: I have extended your 2.2.5 version with IPausableVideoSource (Pause method 
and IsPaused property) for filevideoSource and VideoCaptureDevice, and the 
player with the same method. Drop me a mail if interested!

Original comment by Yves.Van...@gmail.com on 17 Jan 2014 at 5:33

GoogleCodeExporter commented 8 years ago
Hello Yves,

This might be interesting. You may create a "Contribution" code with a patch 
attached.

Regards,
Andrew

Original comment by andrew.k...@gmail.com on 20 Jan 2014 at 8:54

GoogleCodeExporter commented 8 years ago
Hello Yves,

I'm trying to do the same thing, I will be very happy if you share your 
solution!

Best regards!

Marco

Original comment by mortisgo...@hotmail.com on 28 Mar 2014 at 3:33