Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. private async void ScannerSelection_Changed(object sender, SelectionChangedEventArgs args)
  2. {
  3. var selectedScannerInfo = (BarcodeScannerInfo)args.AddedItems[0];
  4. var deviceId = selectedScannerInfo.DeviceId;
  5.  
  6. if (isSelectionChanging)
  7. {
  8. pendingSelectionDeviceId = deviceId;
  9. return;
  10. }
  11.  
  12. do
  13. {
  14. await SelectScannerAsync(deviceId); <- ошибка тут
  15.  
  16. // Stop takes precedence over updating the selection.
  17. if (isStopPending)
  18. {
  19. await CloseScannerResourcesAsync();
  20. break;
  21. }
  22.  
  23. deviceId = pendingSelectionDeviceId;
  24. pendingSelectionDeviceId = null;
  25. } while (!String.IsNullOrEmpty(deviceId));
  26. }
  27.  
  28. private async Task SelectScannerAsync(string scannerDeviceId)
  29. {
  30. isSelectionChanging = true;
  31.  
  32. await CloseScannerResourcesAsync();
  33.  
  34. selectedScanner = await BarcodeScanner.FromIdAsync(scannerDeviceId);
  35.  
  36. if (selectedScanner != null)
  37. {
  38. claimedScanner = await selectedScanner.ClaimScannerAsync();
  39. if (claimedScanner != null)
  40. {
  41. await claimedScanner.EnableAsync();
  42. claimedScanner.Closed += ClaimedScanner_Closed;
  43. ScannerSupportsPreview = !String.IsNullOrEmpty(selectedScanner.VideoDeviceId);
  44. RaisePropertyChanged(nameof(ScannerSupportsPreview));
  45.  
  46. claimedScanner.DataReceived += ClaimedScanner_DataReceived;
  47.  
  48. if (ScannerSupportsPreview)
  49. {
  50. await StartMediaCaptureAsync(selectedScanner.VideoDeviceId);
  51. }
  52. }
  53. else
  54. {
  55. //rootPage.NotifyUser("Failed to claim the selected barcode scanner", NotifyType.ErrorMessage);
  56. }
  57.  
  58. }
  59. else
  60. {
  61. //rootPage.NotifyUser("Failed to create a barcode scanner object", NotifyType.ErrorMessage);
  62. }
  63.  
  64. IsScannerClaimed = claimedScanner != null;
  65. RaisePropertyChanged(nameof(IsScannerClaimed));
  66.  
  67. isSelectionChanging = false;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement