以下代码适用于 CLICK 事件处理程序,但我不能让它自动发送
async void Button_Click_1(object sender, RoutedEventArgs e)
{
SmsDevice smsDevice2 = (SmsDevice)await SmsDevice.GetDefaultAsync();
// Create a text message - Set destination number and message text
SmsTextMessage msg = new SmsTextMessage();
msg.To = "12345678";
msg.Body = "xxxx";
// Send the message asynchronously
await smsDevice2.SendMessageAsync(msg);
}
这不起作用(后台服务)
async void DisplayToastAsync(IBackgroundTaskInstance taskInstance, ManualResetEvent manualEventWaiter)
{
SmsDevice smsDevice2 = (SmsDevice)await SmsDevice.GetDefaultAsync();
// Create a text message - Set destination number and message text
SmsTextMessage msg = new SmsTextMessage();
msg.To = "12345678";
msg.Body = "xxx";
// Send the message asynchronously
await smsDevice2.SendMessageAsync(msg);
}
有谁知道为什么?我该如何解决?