【问题标题】:UWP maintaining barcode scanner D75e - problemUWP 维护条码扫描仪 D75e - 问题
【发布时间】:2019-10-08 10:25:19
【问题描述】:

我初始化了 DeviceWatcher ... 工作正常,我添加了 Honeywell Ring Scanner 它引发了事件 deviceWatcher。当我删除 Honeywell USB Ring Scanner 时,它会引发事件 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】:

    当你断开设备时,它会引发设备移除事件,但所有待处理的操作都需要正确取消,所有资源都需要清理。请参考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;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多