【问题标题】:email compose task is not working windows phone 8.1电子邮件撰写任务不工作 Windows Phone 8.1
【发布时间】:2014-08-15 06:31:41
【问题描述】:

如何在 windows phone 8.1 应用中使用按钮发送电子邮件?

EmailRecipient sendTo = new EmailRecipient()
{
    Address = "abc@outlook.com"
};

//generate mail object
EmailMessage mail = new EmailMessage();
mail.Subject = "Feedback";


//add recipients to the mail object
mail.To.Add(sendTo);
//mail.Bcc.Add(sendTo);
//mail.CC.Add(sendTo);

//open the share contract with Mail only:
await EmailManager.ShowComposeNewEmailAsync(mail);

我收到错误消息:

"错误 1 ​​'await' 运算符只能在异步方法中使用。 考虑使用 'async' 修饰符标记此方法并更改 其返回类型为 'Task'。”

【问题讨论】:

  • 我认为错误信息很清楚...
  • 如果您使用的是 await,请将您的方法设为异步。

标签: c# windows-phone-8.1


【解决方案1】:

您需要使用async 关键字标记您的事件处理程序,以便能够在其中await

public async void MyButtonHandler(object sender, EventArgs e)
{
   EmailRecipient sendTo = new EmailRecipient()
   {
       Address = "abc@outlook.com"
   };

   //generate mail object
   EmailMessage mail = new EmailMessage();
   mail.Subject = "Feedback";

   //add recipients to the mail object
   mail.To.Add(sendTo);
   //mail.Bcc.Add(sendTo);
   //mail.CC.Add(sendTo);

   //open the share contract with Mail only:
   await EmailManager.ShowComposeNewEmailAsync(mail);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多