// Closes the current {@link CameraDevice}.
        protected void CloseCamera()
        {
            if (CaptureSession == null)
            {
                return;
            }

            try
            {
                CameraOpenCloseLock.Acquire();
                if (null != CaptureSession)
                {
                    try
                    {
                        CaptureSession.StopRepeating();
                        CaptureSession.AbortCaptures();
                    }
                    catch (CameraAccessException ex)
                    {
#if DEBUG
                        ex.PrintStackTrace();
#endif
                    }
                    catch (IllegalStateException ex)
                    {
#if DEBUG
                        ex.PrintStackTrace();
#endif
                    }

                    CaptureSession.Close();
                    CaptureSession = null;
                }

                if (null != CameraDevice)
                {
                    CameraDevice.Close();
                    CameraDevice = null;
                }

                if (null != _imageReader)
                {
                    _imageReader.Close();
                    _imageReader = null;
                }
            }
            catch (InterruptedException ex)
            {
                throw new RuntimeException("Interrupted while trying to lock camera closing.", ex);
            }
            finally
            {
                CameraOpenCloseLock.Release();
            }
        }