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 服務或控制行動寬頻裝置的使用者模式驅動程式,則此事件可讓您實作前景事件處理常式來接收及處理裝置服務通知。