Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:31:54+00:00 2026-06-02T17:31:54+00:00

I am trying to write a basic camera app using the auto-focus feature to

  • 0

I am trying to write a basic camera app using the auto-focus feature to process a barcode. If I press back just as the camera has focused, it goes to a blank screen and just hangs there – no exception is thrown. I have traced the problem to the CaptureImage() method, I can see it being called, but the OnCaptureImageAvailable method is never invoked. This happens even when I do not unhook the OnCaptureImageAvailable in the OnNavigatedFrom method.

   protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedFrom(e);
        _camera.AutoFocusCompleted -= OnCameraAutoFocusCompleted;
        _camera.CaptureImageAvailable -= OnCaptureImageAvailable;
        _camera.Initialized -= OnCameraInitialized;
        _camera.Dispose();
        _camera = null;
    }

    private void InitializeCamera()
    {
        _camera = new PhotoCamera();
        _camera.Initialized += OnCameraInitialized;
        viewfinderBrush.SetSource(_camera);
    }

    void OnCameraInitialized(object sender, EventArgs e)
    {
        _camera.Initialized -= OnCameraInitialized;
        _camera.AutoFocusCompleted += OnCameraAutoFocusCompleted;
        _camera.CaptureImageAvailable += OnCaptureImageAvailable;

        _camera.FlashMode = FlashMode.Off;
        _camera.Focus(); 
    }

    private void OnCameraAutoFocusCompleted(object sender, EventArgs e)
    {
        _camera.CaptureImage();
    }

    private void OnCaptureImageAvailable(object sender, ContentReadyEventArgs e)
    {
        if (_camera != null && e.ImageStream != null)
            ScanBarcode(e);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:31:56+00:00Added an answer on June 2, 2026 at 5:31 pm

    The issue is you are going to the previous page and disposing the camera while the camera is busy capturing the image in “_camera.CaptureImage();”.

    How about keeping two boolean flags: “doBack” and “captureCompleted”.

    Then, do not go back when the OnCameraAutoFocusCompleted event triggers:

    private void OnCameraAutoFocusCompleted(object sender, EventArgs e)
        {
            _camera.CaptureImage();
        }
    

    When the back key is pressed set the doBack flag and ignore, unless captureCompleted is set:

    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (!captureCompleted)
            {
                this.doBack = true;
                e.Cancel = true;
            }
    
            base.OnBackKeyPress(e);
        }
    

    Then, when the OnCameraCaptureCompleted event triggers, set the captureCompleted flag en go to the previous page (and dispose the camera) if the doBack flag is set:

    private void OnCameraCaptureCompleted(object sender, EventArgs e)
        {
            this.captureCompleted = true;
    
            if (doBack)
            { 
                this.Dispatcher.BeginInvoke(delegate()
                {
                    NavigationService.GoBack();
                });
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a basic drawing widget using the Tkinter library. The very
I have a c# app and I'm trying to write a basic login form
I am trying to write a simple C calculator script, using only the basic
I'm trying to write a simple game to teach some basic Welsh using the
I'm trying to write a basic vertex shader in GLSL and just for the
Im trying to write a very basic android app that displays around 5 pictures
I'm trying to write a Spring configuration for some basic Google App Engine services.
I am trying to write a basic app that will read data off a
I'm trying to write a basic augmented reality app in Android, but I'm running
I'm trying to write basic assert test: def assert_session_has ( sessionvar ) return assert_not_nil

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.