条码扫描不允许用户移动条码扫描两次

Scanning of barcode not letting user move barcode scans twice

我正在使用 zxing 扫描仪,它工作得很好,但出于某种原因,它会扫描同一个条形码两次。我已经放置了一个线程延迟以尝试保持视口打开但允许操作员有时间将设备从条形码移开但不幸的是他们报告它扫描了两次但我们不想关闭视口.

但是要补充一点,我不想关闭 ZXingScannerView 只是暂停它,以便给用户足够的时间来准备好下一个条形码

下面的代码是在按钮点击按钮下,他们没有点击按钮两次,它的扫描甚至是 hapeneing 两次。

ZXingDefaultOverlay overlay;        
ZXingScannerView zxing;  
zxing = new ZXingScannerView
{
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            AutomationId = "zxingScannerView",
};


zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread(async () =>
{               

    BarCode = result.Text;

    await PlayBeep();
    await Task.Delay(2000); //This is the delay I was given so that it would not scan right away again but leave the view open
    overlay = new ZXingDefaultOverlay
        {
            TopText = "Hold your phone up to the barcode",
            BottomText = "Scanning will happen automatically",
            ShowFlashButton = zxing.HasTorch,
            AutomationId = "zxingDefaultOverlay",

        };
        var grid = new Grid
        {
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand,
        };
        grid.Children.Add(zxing);
        grid.Children.Add(overlay);

        // The root page of your application
        Content = grid;
}

我这样做了,把scanPage.IsScanning = false;防止两次reader

    ZXingScannerPage scanPage;
    SendData sd;

    private async void Btnpe001_Clicked(object sender, System.EventArgs e)
    {
        scanPage = new ZXingScannerPage();
        sd = new SendData();

        await Navigation.PushAsync(scanPage);

        scanPage.OnScanResult += (result) =>
        {
            scanPage.IsScanning = false;

            Device.BeginInvokeOnMainThread(async () =>
            {
                sd.Action = "personentry";
                sd.DataToSend = result.Text;
                await sd.SendAsync();

                await Navigation.PopAsync();
                await DisplayAlert("Autenticado", result.Text, "OK");

            });
        };

    }

对于其他人,您可以使用 zxing 选项函数 DelayBetweenContinuousScans

zxing = new ZXingScannerView
{
     HorizontalOptions = LayoutOptions.FillAndExpand,
     VerticalOptions = LayoutOptions.FillAndExpand,
     AutomationId = "zxingScannerView",
};
zxing.Options = new MobileBarcodeScanningOptions()
{
  DelayBetweenContinuousScans = 2000
};