MobileBroadbandDeviceServiceCommandSession.CommandReceived 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
打开会话后,从 MobileBroadbandDeviceServiceCommandSession 对象上的移动宽带设备收到未经请求的事件时引发。
注意
此功能仅适用于由移动网络运营商授予特权访问权限的移动运营商应用和 UWP 应用。
如果要使用此 API 并将应用发布到 Microsoft Store,则需要获得特殊批准。 有关详细信息,请参阅应用功能声明主题中的受限功能部分。
// 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)
事件类型
TypedEventHandler<MobileBroadbandDeviceServiceCommandSession,MobileBroadbandDeviceServiceCommandEventArgs>
Windows 要求
设备系列 |
Windows 11, version 24H2 (在 10.0.26100.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v19.0 中引入)
|
应用功能 |
cellularDeviceControl
|
示例
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();
}
}
}
注解
如果要开发控制移动宽带设备的 NT 服务或用户模式驱动程序,则此事件允许你实现前台事件处理程序来接收和处理设备服务通知。