UWP维护条形码扫描仪D75e-问题

问题描述 投票:0回答:1

我初始化了DeviceWatcher ...效果很好,我添加了Honeywell Ring Scanner,它引发了事件deviceWatcher。当我删除霍尼韦尔USB环形扫描仪时,它将引发事件DeviceWatcher_Removed,其中我将ClaimedBarcodeScannerBarcodeScanner对象为空,并且将DeviceWatcher _Updated返回状态为STOP

我连接Ring Scanner后,在App中什么也没发生。如果我重新启动该应用程序,则在我断开连接并连接Ring Scanner之前,它是可行的。

我需要从应用中释放BrcodeScanner

我尝试Honeywell D75e Win 10 iotHoneywell Ring Scanner 8620903

我也尝试释放内存...

GC.Collect();
GC.WaitForPendingFinalizers();

我试图处理ClaimedBarcodeScanner

c# barcode-scanner windows-10-iot-core honeywell
1个回答
0
投票

当断开设备的连接时,它将引发设备删除事件,但是所有未决的操作都需要正确取消,并且所有资源都需要清理。请参考EventHandlerForDevice中的以下代码。代码中的回调用于显式关闭设备,以清理资源,正确处理错误并停止与断开连接的设备通信。

    private async void CloseCurrentlyConnectedDevice()
    {
        if (device != null)
        {
            // Notify callback that we're about to close the device
            if (deviceCloseCallback != null)
            {
                deviceCloseCallback(this, deviceInformation);
            }

            // This closes the handle to the device
            device.Dispose();

            device = null;
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.