Open gartaud opened 11 months ago
After debugging further, it turns out that the issue is that the callback upon detecting a barcode is made from a worker thread that is different from the thread that registered the callback.
While this makes sense, it would be good to explain in the documentation that the callback is made from a different thread.
I have the same error even if I ensure that the operation is made in the main thread:
protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
{
MainThread.BeginInvokeOnMainThread(() =>
{
barcodeView.IsDetecting = false;
ViewModel.HandleBarcodeDetected(e);
});
}
How did you solved it?
protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
{
var first = e.Results?.FirstOrDefault();
if (first is not null)
{
Dispatcher.Dispatch(() =>
{
// Update BarcodeGeneratorView
barcodeGenerator.ClearValue(BarcodeGeneratorView.ValueProperty);
barcodeGenerator.Format = first.Format;
barcodeGenerator.Value = first.Value;
// Update Label
ResultLabel.Text = $"Barcodes: {first.Format} -> {first.Value}";
});
}
}
As in https://github.com/Redth/ZXing.Net.Maui/blob/main/BigIslandBarcode/MainPage.xaml.cs
Hello
I tried the control for a proof-of-concept app using VS 2022 preview 5.
Everything seems fine until the control detects a QR code. Then the control crashes and brings the app down before the user event handler is called.
Is that expected? Thanks.