public async Task <bool> ReleaseScannerAsync(bool exit) { try { if (claimedScanner != null) { claimedScanner.DataReceived -= ClaimedScanner_DataReceivedAsync; claimedScanner.ReleaseDeviceRequested -= OnClaimedScannerReleaseDeviceRequested; claimedScanner.IsDecodeDataEnabled = false; await claimedScanner.DisableAsync(); claimedScanner.Dispose(); } scanner = null; } catch (Exception ex) { //Console.WriteLine(ex.Message); return(false); } return(true); }
protected override async void OnNavigatedFrom(NavigationEventArgs e) { using (ExitLocker) { await Task.Run(() => { ExitLocker.WaitOne(); }); } if (Capture != null) { using (Capture) { await Capture.StopPreviewAsync(); PreviewControl.Source = null; } } if (ClaimedScanner != null) { using (ClaimedScanner) { await ClaimedScanner.StopSoftwareTriggerAsync(); await ClaimedScanner.DisableAsync(); ClaimedScanner.DataReceived -= ClaimedScanner_DataReceived; } } BarcodeHistory.Clear(); BarcodeHistory = null; ExitLocker = null; Capture = null; ClaimedScanner = null; }