我目前正在使用C#为Outlook构建一个插件,但是当我在线程中创建新的电子邮件项目时,如果我向电子邮件添加附件,我的Outlook会阻止用户界面(冻结),直到创建电子邮件。
如果我不添加不阻止用户界面Outlook的附件。
那么我该如何解决这个问题(不阻止用户界面展望)?
这是我的代码:
在Ribbon.cs中,我点击了功能按钮:
private void button2_Click(object sender, RibbonControlEventArgs e){
Globals.ThisAddIn.CheckProcessEmail();
}
和函数CheckProcessEmail,我创建了新的Thread:
public void CheckProcessEmail(){
Thread threadCheckTest = new Thread(CheckTest);
threadCheckTest.Start();
}
public static void CheckTest(){
Outlook.Application application = Globals.ThisAddIn.Application;
Outlook.MailItem item = application.CreateItem((Outlook.OlItemType.olMailItem));
Outlook.MAPIFolder sentBox = (Outlook.MAPIFolder)Globals.ThisAddIn.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
Outlook.MailItem email = (Outlook.MailItem)sentBox.Items.Add();
email.Subject = "Send Test";
email.HTMLBody = "<div class=WordSection1><p class=MsoNormal>sad<o:p></o:p></p></div><b>Strong</b><h1>Hello</h1>";
email.To = "a@test.com;b@test.com;c@test.com";
email.BCC = "cc@test.com";
email.Attachments.Add(@attachmentPath, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
email.Save();
}