Share via


MobileBroadbandDeviceServiceCommandSession.CommandReceived Événement

Définition

Déclenché lorsqu’un événement non sollicité est reçu d’un appareil haut débit mobile sur l’objet MobileBroadbandDeviceServiceCommandSession après l’ouverture de la session.

Notes

Cette fonctionnalité est disponible uniquement pour les applications d’opérateur mobile et les applications UWP disposant d’un accès privilégié par les opérateurs de réseau mobile.

Si vous souhaitez utiliser cette API et publier votre application sur le Microsoft Store, vous aurez besoin d’une approbation spéciale. Pour plus d’informations, consultez la section Fonctionnalités restreintes dans la rubrique Déclarations des fonctionnalités d’application .

// Register
event_token CommandReceived(TypedEventHandler<MobileBroadbandDeviceServiceCommandSession, MobileBroadbandDeviceServiceCommandEventArgs const&> const& handler) const;

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

// Revoke with event_revoker
MobileBroadbandDeviceServiceCommandSession::CommandReceived_revoker CommandReceived(auto_revoke_t, TypedEventHandler<MobileBroadbandDeviceServiceCommandSession, MobileBroadbandDeviceServiceCommandEventArgs const&> const& handler) const;
public event TypedEventHandler<MobileBroadbandDeviceServiceCommandSession,MobileBroadbandDeviceServiceCommandEventArgs> CommandReceived;
function onCommandReceived(eventArgs) { /* Your code */ }
mobileBroadbandDeviceServiceCommandSession.addEventListener("commandreceived", onCommandReceived);
mobileBroadbandDeviceServiceCommandSession.removeEventListener("commandreceived", onCommandReceived);
- or -
mobileBroadbandDeviceServiceCommandSession.oncommandreceived = onCommandReceived;
Public Custom Event CommandReceived As TypedEventHandler(Of MobileBroadbandDeviceServiceCommandSession, MobileBroadbandDeviceServiceCommandEventArgs) 

Type d'événement

Configuration requise pour Windows

Famille d’appareils
Windows 11 Insider Preview (introduit dans 10.0.26100.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v19.0)
Fonctionnalités de l’application
cellularDeviceControl

Exemples

using System;
using System.Threading;
using Windows.Foundation;
using Windows.Networking.NetworkOperators;

public class MobileBroadbandDeviceServiceCommandEventSample
{
    private const string sampleServiceId = "abcdefg-1234-abcd-1234-abcd1234abcd";
    private AutoResetEvent dsCommandReceivedEvent = new AutoResetEvent(false);

    public void DeviceServiceCommandSessionCommandReceived()
    {
        var modem = MobileBroadbandModem.GetDefault();
        if (modem == null)
        {
            // Handle the error.
            return;
        }

        MobileBroadbandDeviceService sampleService = modem.GetDeviceService(new Guid(sampleServiceId));
        if (sampleService == null)
        {
            // Handle the error.
            return;
        }

        var commandSession = sampleService.OpenCommandSession();
        commandSession.CommandReceived +=
                    new TypedEventHandler<MobileBroadbandDeviceServiceCommandSession,
                        MobileBroadbandDeviceServiceCommandEventArgs>(this.CommandReceivedHandler);

        bool CommandReceived = dsCommandReceivedEvent.WaitOne(10000);
        if (!CommandReceived)
        {
            // Handle the error.
        }

        commandSession.CommandReceived -= this.CommandReceivedHandler;
    }

    private void CommandReceivedHandler(MobileBroadbandDeviceServiceCommandSession sender,
        MobileBroadbandDeviceServiceCommandEventArgs e)
    {
        if (e != null)
        {
            Console.WriteLine("Received device service event");
            Console.WriteLine("  DeviceId: " + e.DeviceId);
            Console.WriteLine("  DeviceServiceId: " + e.DeviceServiceId);
            Console.WriteLine("  EventId: " + e.EventId);
            Console.WriteLine("  Received data: " + e.ReceivedData);
            dsCommandReceivedEvent.Set();
        }
    }
}

Remarques

Si vous développez un service NT ou un pilote en mode utilisateur qui contrôle les appareils haut débit mobiles, cet événement vous permet d’implémenter un gestionnaire d’événements de premier plan pour recevoir et gérer les notifications de service d’appareil.

S’applique à