Partager via


ClaimedBarcodeScanner.ReleaseDeviceRequested Événement

Définition

Se produit lorsque l’appareil reçoit une demande de libération de sa revendication exclusive.

// Register
event_token ReleaseDeviceRequested(EventHandler<ClaimedBarcodeScanner> const& handler) const;

// Revoke with event_token
void ReleaseDeviceRequested(event_token const* cookie) const;

// Revoke with event_revoker
ClaimedBarcodeScanner::ReleaseDeviceRequested_revoker ReleaseDeviceRequested(auto_revoke_t, EventHandler<ClaimedBarcodeScanner> const& handler) const;
public event System.EventHandler<ClaimedBarcodeScanner> ReleaseDeviceRequested;
function onReleaseDeviceRequested(eventArgs) { /* Your code */ }
claimedBarcodeScanner.addEventListener("releasedevicerequested", onReleaseDeviceRequested);
claimedBarcodeScanner.removeEventListener("releasedevicerequested", onReleaseDeviceRequested);
- or -
claimedBarcodeScanner.onreleasedevicerequested = onReleaseDeviceRequested;
Public Custom Event ReleaseDeviceRequested As EventHandler(Of ClaimedBarcodeScanner) 

Type d'événement

Exemples

L’exemple suivant montre comment configurer le gestionnaire d’événements.

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();
    }); 
}

Remarques

Si votre application reçoit un événement ReleaseDeviceRequested d’une autre application, elle peut perdre sa revendication exclusive, sauf si votre application conserve l’appareil.

S’applique à

Voir aussi