Share via


BarcodeScanner.GetDefaultAsync Method

Definition

Returns the first available barcode scanner.

public:
 static IAsyncOperation<BarcodeScanner ^> ^ GetDefaultAsync();
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<BarcodeScanner> GetDefaultAsync();
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<BarcodeScanner> GetDefaultAsync();
function getDefaultAsync()
Public Shared Function GetDefaultAsync () As IAsyncOperation(Of BarcodeScanner)

Returns

The first available barcode scanner. Returns a null object in the following cases:

  • A device is not found.
  • Access denied to the existing device. The user can deny access to a device, which is not treated as an exception.
Attributes

Examples

// Creates the barcode scanner.
task<void> Scenario1::CreateDefaultScannerObject()
{
    return create_task(BarcodeScanner::GetDefaultAsync()).then([this] (BarcodeScanner^ _scanner)
    {
        this->scanner = _scanner;
        if (this->scanner != nullptr)
        {			
            // UpdateOutput("Barcode Scanner created.");
            // UpdateOutput("Device Id is:" + this->scanner->DeviceId);
        }
        else
        {
            // UpdateOutput("Barcode scanner not found. Connect a barcode scanner.");
        }
    });

}
//Creates a barcode scanner.

private async Task<bool> CreateDefaultScannerObject()
{
    if (scanner == null)
    {
        scanner = await BarcodeScanner.GetDefaultAsync();

        if (scanner != null)
        {
            // UpdateOutput("Default Barcode Scanner created.");
            // UpdateOutput("Device Id is:" + scanner.DeviceId);
        }
        else
        {
            // UpdateOutput("Barcode Scanner not found. Please connect a Barcode Scanner.");
            return false;
        }
    }
    return true;
}

Applies to

See also