Leggere in inglese

Condividi tramite


ClaimedBarcodeScanner.ReleaseDeviceRequested Evento

Definizione

Si verifica quando il dispositivo ottiene una richiesta per rilasciare la relativa attestazione esclusiva.

public event System.EventHandler<ClaimedBarcodeScanner> ReleaseDeviceRequested;

Tipo evento

Esempio

Nell'esempio seguente viene illustrato come configurare il gestore eventi.

void Scenario1::ScenarioStartScanButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
     // Create the barcode scanner. 
    create_task(CreateDefaultScannerObject()).then([this](void)
    {
        if (scanner != nullptr)
        {
            // Claim the scanner for exclusive use by your application.
            create_task(ClaimScanner()).then([this](void)
            {
                if (claimedScanner)
                {
                        
                    // Add a release device requested event handler. If this event is not handled,  
                    // another app can claim the barcode scanner.
                    releaseDeviceRequestedToken = claimedScanner->ReleaseDeviceRequested::add(ref new EventHandler<ClaimedBarcodeScanner^>(this, &Scenario1::OnReleaseDeviceRequested));

  
                    /// Add a data receive event handler.
                    dataReceivedToken =  claimedScanner->DataReceived::add(ref new TypedEventHandler<ClaimedBarcodeScanner^, BarcodeScannerDataReceivedEventArgs^>(this, &Scenario1::OnDataReceived));
                    UpdateOutput("Attached the DataReceived Event handler.");

                    // Set the app to decode the raw data from the barcode scanner 
                    claimedScanner->IsDecodeDataEnabled = true;

                    // Enable the scanner.
                    create_task(EnableScanner()).then([this](void)
                    {
                        UpdateOutput("Ready to Scan.");

                        // Reset the button state
                        ScenarioEndScanButton->IsEnabled = true;
                        ScenarioStartScanButton->IsEnabled = false;
                    });
                }
            });
        }
    });

}
private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs e)
{
    // Create the barcode scanner. 
    if (await CreateDefaultScannerObject())
    {
        // Claim the scanner for exclusive use by your application.
        if (await ClaimScanner())
        {
            
            // Add a release device requested event handler. If this event is not handled,  
            // another app can claim the barcode scanner.
            claimedScanner.ReleaseDeviceRequested += claimedScanner_ReleaseDeviceRequested;

            // Add a data receive event handler.
            claimedScanner.DataReceived += claimedScanner_DataReceived;
            UpdateOutput("Attached the DataReceived Event handler.");

            // Set the app to decode the raw data from the barcode scanner 
            claimedScanner.IsDecodeDataEnabled = true;

            // Enable the scanner.
            if (await EnableScanner())
            {
                // Reset the button state
                ScenarioEndScanButton.IsEnabled = true;
                ScenarioStartScanButton.IsEnabled = false;

                UpdateOutput("Ready to Scan.");
            }
        } 
    }
    else
    {
        UpdateOutput("No Barcode Scanner found");
    }
}
void Scenario1::OnReleaseDeviceRequested(Platform::Object ^sender, Windows::Devices::PointOfService::ClaimedBarcodeScanner ^args)
{
    Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler( 
        [this,args]() 
    {
        args->RetainDevice(); 
        UpdateOutput("Received event ReleaseDeviceRequested. Retaining the barcode scanner.");
    }));
}
async void claimedScanner_ReleaseDeviceRequested(object sender, ClaimedBarcodeScanner e)
{
    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
    {
        e.RetainDevice();
    }); 
}

Commenti

Se l'applicazione riceve un evento ReleaseDeviceRequested da un'altra applicazione, può perdere l'attestazione esclusiva a meno che l'applicazione non mantenga il dispositivo.

Si applica a

Prodotto Versioni
WinRT Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100

Vedi anche