我目前正在使用 Visual Studio 2013 使用 Office 2013 加载项。我创建了一个带有显示小 Windows 窗体的按钮的功能区:
private void outterMailCreateNewFaxBTN_Click(object sender, RibbonControlEventArgs e)
{
CreateNewFax cnf = new CreateNewFax(this);
cnf.Show();
}
当用户单击表单上的其中一个按钮时,将创建一个新的 MailItem(其中包含一些信息)。
private void button1_Click(object sender, EventArgs e)
{
this.Dispose();
this.outterMailRibbon.setFaxNumber(faxNumber, this);
}
这是 setFaxNumber 方法:
public void setFaxNumber(String faxNumber, CreateNewFax cnf)
{
cnf = null;
//mother.Dispose();
this.faxNumber = faxNumber;
Outlook.Application application = Globals.ThisAddIn.Application;
Outlook.MailItem myMailItem = (Outlook.MailItem)application.CreateItem(Outlook.OlItemType.olMailItem);
myMailItem.To = this.faxNumber;
myMailItem.Subject = "[FAX:" + this.faxNumber + "]";
myMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
((Outlook.ItemEvents_10_Event)myMailItem).Send += new Microsoft.Office.Interop.Outlook.ItemEvents_10_SendEventHandler(ThisAddIn_Send);
this.gMailItem = myMailItem;
myMailItem.Display(true);
}
我目前面临的问题是,在用户单击表单上的特定按钮后,Outlook 主进程被阻止并且 UI 冻结,直到新创建的消息被发送或丢弃。
我怎样才能避免这种行为(以便用户能够显示来自 Outlook 的其他邮件,而这个新创建的 MailItem 仍然可以由用户编辑)?
编辑:创建 MailItem 后 Outlook-UI 冻结。当时,Windows 窗体仍然打开,我可以像往常一样使用 Outlook-UI。