WP7 BarcodeManager - Invalid cross-thread access

Posted by rpf on Stack Overflow See other posts from Stack Overflow or by rpf
Published on 2012-03-21T21:56:26Z Indexed on 2012/03/21 23:29 UTC
Read the original article Hit count: 183

I'm trying to use Windows Phone 7 Silverlight ZXing Barcode Scanning Library but I'm having some problems.

I'm using a background worker to check the image, but when I do this:

WP7BarcodeManager.ScanBarcode(this.Image, BarcodeResults_Finished);

The code throws an exception: Invalid cross-thread access.

Here is my code...

void photoChooserTask_Completed(object sender, PhotoResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            ShowImage();

            System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
            bmp.SetSource(e.ChosenPhoto);

            imgCapture.Source = bmp;
            this.Image = new BitmapImage();
            this.Image.SetSource(e.ChosenPhoto);

            progressBar.Visibility = System.Windows.Visibility.Visible;
            txtStatus.Visibility = System.Windows.Visibility.Collapsed;

            worker.RunWorkerAsync();
        }
        else
            ShowMain();
    }

void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Thread.Sleep(2000);

                WP7BarcodeManager.ScanMode = com.google.zxing.BarcodeFormat.UPC_EAN;
                WP7BarcodeManager.ScanBarcode(this.Image, BarcodeResults_Finished);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error processing image.", ex);
            }
        }

How can I solve this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about windows-phone-7