我想使用Windows Phone 7 Silverlight ZXing條碼掃描庫,但我有一些問題。WP7 BarcodeManager - 無效的跨線程訪問
我使用的是後臺工作,檢查圖像,但是當我這樣做:
WP7BarcodeManager.ScanBarcode(this.Image, BarcodeResults_Finished);
代碼拋出一個異常:無效的跨線程訪問。
這裏是我的代碼...
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);
}
}
我該如何解決這個問題?
你爲什麼不把WP7BarcodeManager.ScanBarcode調用到你的photoChooserTask_Completed方法中?它會解決問題。 – 2012-03-21 22:29:06
因爲我想在API正在處理圖像時顯示進度條。 – rpf 2012-03-21 22:32:02