This project is read-only.

Problems trying to stop and dispose camera

Nov 4, 2009 at 9:17 AM

Hi Tamir, thanks for this great code :)

I'm using your webcam control inside of different windows (but only one at the same time). So, I need to open a new windows, show images from the camera; close this windows and open it again. However, when I open again the windows, it doesn't work. I think it's some problem trying to dispose the camera resource.

An option that I've tried, but it doesn't work at all, is to stop the image feeding, and then, close the windows. In that case, when I open again the windows, it works. However, to stop the image feeding is very slow. It takes a long time to dispose the camera or it doesn't always do it.

In the next link, I've published a simple test VS project to show you what I'm trying to do:

Note: I''ve tried with 3 different webcambs, and the result is the same in all of them.

Thank you very much!

Nov 18, 2011 at 11:08 AM

Hi there! Thank for this project, Tamir ^^

Did anyone manage to solve this problem? I'm facing it too...

Thanks a lot! :-)

Jul 26, 2013 at 1:24 PM

Why don't you stop the player when you close the windows?
    public Window1()

        this.Closed += (sender, args) => player.Stop();
otherwise if you wanted, i find an upgrade of this solution :
Dec 19, 2013 at 12:18 PM
Edited Dec 19, 2013 at 12:20 PM
    private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
It will work.
Apr 22, 2015 at 8:54 AM
I tried many way, so i find this way to Stop my Webcam Device. But i can't understand how it can do :)
Anyone can show me why?

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        if (webcamPlayer != null && webcamPlayer.Device != null)

            CommandBindings.Remove(new CommandBinding(Input.CaptureImageCommands.CaptureImage,
            new ExecutedRoutedEventHandler(CaptureImage_Executed), new CanExecuteRoutedEventHandler(CaptureImage_CanExecute)));
            CommandBindings.Remove(new CommandBinding(Input.CaptureImageCommands.RemoveImage,
                new ExecutedRoutedEventHandler(RemoveImage_Executed)));
            CommandBindings.Remove(new CommandBinding(Input.CaptureImageCommands.ClearAllImages,
                new ExecutedRoutedEventHandler(ClearAllImages_Executed)));

            BitmapSource bitmap = webcamPlayer.CurrentBitmap;
            if (bitmap != null)
            //SelectedWebcamMonikerString =  "";