Shut Off Camera?

Jul 3, 2013 at 4:44 PM
Hi

I am wondering what is the best way to temporary shut off the scanning(ie the camera). I have a panorama view that loads up the zxing.net but when I go to the next item, I want to stop the camera(or at least stop it from taking pictures).

I tried disposing the photoCamera object but this seems to be slow.
Developer
Jul 3, 2013 at 5:04 PM
Are you familiar with the TPL (task parallel library)?
Try to dispose the PhotoCaptureDebice through a task, so that the UI thread isn't involved. I can take a second or two to dispose.

Why do your want to dispose the pcd? Battery lifetime?
Jul 3, 2013 at 7:04 PM
fabianhenzler wrote:
Are you familiar with the TPL (task parallel library)?
Try to dispose the PhotoCaptureDebice through a task, so that the UI thread isn't involved. I can take a second or two to dispose.

Why do your want to dispose the pcd? Battery lifetime?
Well mainly because I have a manual view to type in barcodes(backup for if the barcode can't be scanned) and when I switch to it I the scanner is still running and camera is flashing and trying to take pictures and makes it look weird.

I done a little bit with TPL but not too much, will take a look at it.
Jul 29, 2013 at 8:53 PM
chobo2 wrote:
fabianhenzler wrote:
Are you familiar with the TPL (task parallel library)?
Try to dispose the PhotoCaptureDebice through a task, so that the UI thread isn't involved. I can take a second or two to dispose.

Why do your want to dispose the pcd? Battery lifetime?
Well mainly because I have a manual view to type in barcodes(backup for if the barcode can't be scanned) and when I switch to it I the scanner is still running and camera is flashing and trying to take pictures and makes it look weird.

I done a little bit with TPL but not too much, will take a look at it.
Hmm finally got around to see if I can fix this but Wp7 does not seem to have TPL.
Jul 29, 2013 at 10:19 PM
Edited Jul 29, 2013 at 10:25 PM
Hmm finally got around to see if I can fix this but Wp7 does not seem to have TPL.
Good news: It is there.

I have used it, with VS2010. In fact, I reworked the internals of an app that I had published on the WP market months before, just to use it as a live excercise (and made it more responsive along the way). It worked just fine, could not detect any bugs or unexpected behaviour and most important, the app passed store certification just fine.

UPDATE: Information below may be outdated...
The installation process must be followed to the letter, but it is easy to follow.  Keep an eye on two specific Windows Updates which must be removed (if already installed) and never installed (ignored) for this to install successfully, it is all documented.  The updates are KB2645410 and KB2635973. They do not interfere with the functionality but with the installation of the CTP.  Up to this day I have them in the "hidden updates" on both my desktop and laptop.
Honestly, I'd feel lost without this CTP when writing WP code, both 7 and 8 :D
  1. Here is the official download: http://www.microsoft.com/en-us/download/details.aspx?id=9983
  2. And here is the project's page: http://blogs.msdn.com/b/lucian/archive/2011/04/13/async-ctp-refresh-installation.aspx - this project's page contains pointers and descriptions to an older versions but the important part is that it gives insight to what gets installed, why and where.
My own AsyncCtpLibrary_Phone.dll is version 1.1. I have no idea whether it is the latest or not, but is the app I have published on the WP store uses.
Jul 29, 2013 at 10:43 PM
andress wrote:
Hmm finally got around to see if I can fix this but Wp7 does not seem to have TPL.
Good news: It is there.

I have used it, with VS2010. In fact, I reworked the internals of an app that I had published on the WP market months before, just to use it as a live excercise (and made it more responsive along the way). It worked just fine, could not detect any bugs or unexpected behaviour and most important, the app passed store certification just fine.

UPDATE: Information below may be outdated...
The installation process must be followed to the letter, but it is easy to follow.  Keep an eye on two specific Windows Updates which must be removed (if already installed) and never installed (ignored) for this to install successfully, it is all documented.  The updates are KB2645410 and KB2635973. They do not interfere with the functionality but with the installation of the CTP.  Up to this day I have them in the "hidden updates" on both my desktop and laptop.
Honestly, I'd feel lost without this CTP when writing WP code, both 7 and 8 :D
  1. Here is the official download: http://www.microsoft.com/en-us/download/details.aspx?id=9983
  2. And here is the project's page: http://blogs.msdn.com/b/lucian/archive/2011/04/13/async-ctp-refresh-installation.aspx - this project's page contains pointers and descriptions to an older versions but the important part is that it gives insight to what gets installed, why and where.
My own AsyncCtpLibrary_Phone.dll is version 1.1. I have no idea whether it is the latest or not, but is the app I have published on the WP store uses.
I will check it out, I found this nuget package and trying it out. I forgot my phone cable so I can't test if it works right now.
Jul 31, 2013 at 5:10 PM
Hmm does not seem to be working. Still has that delay, also crashes if you go to many times back and forth.

I guess I could put a try catch around to stop it from crashing but not sure why it is crashing would have though that my checks to see if the camera object was disposed would stop it.
      private void PhotoCameraOnInitialized(object sender,
                                         CameraOperationCompletedEventArgs cameraOperationCompletedEventArgs)
        {
            width = Convert.ToInt32(photoCamera.PreviewResolution.Width);
            height = Convert.ToInt32(photoCamera.PreviewResolution.Height);

            luminance = new PhotoCameraLuminanceSource(width, height);

            photoCamera.Focus();

        }
Will crash if I go back and forth a few times right away in that method.

I have this
 protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            Parallel.Invoke(() => Dispose());
            base.OnNavigatedFrom(e);
        }

  private void Panorama_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var panorama = (Panorama)sender;

            if (panorama.SelectedIndex == 1)
            {
                Parallel.Invoke(() => Dispose());

            }
            else
            {
                InitializeAndGo();
            }
        }

    public void Dispose()
        {
            if (photoCamera != null)
            {
                photoCamera.Dispose();
                photoCamera = null;
            }
        }
Mar 5 at 4:24 PM
Hey

I upgraded to Windows Phone 8, But now I can't use the Nuget Package anymore as it only works with Windows Phone 7. How do I do this Parallel stuff in Windows Phone 8?