![](/img/trans.png)
[英]How can I call a method in the background without “The function evaluation requires all threads to run”
[英]Can i run outlook add-on method in background process when load function call?
這是我的代碼,有兩種方法,一種是通知郵件,它在Outlook中收到新郵件時調用。 第二種方法是mailProcessTrigger,它在郵件中執行一些更改。 我想在另一個線程上運行mailProcessTrigger()方法,並且每5分鍾調用一次。 我無法使該方法成為多線程。
namespace PhishCOP
{
public partial class Phishing
{
Outlook.Application outlookApp;
Outlook.MAPIFolder deleterFolder = null;
Outlook.Items mailItems = null;
Outlook.MAPIFolder inboxFolder = null;
Outlook.Items items;
string SchemaTransportHeader = @"http://schemas.microsoft.com/mapi/proptag/0x007D001E";
const string PR_ATTACH_DATA_BIN = "http://schemas.microsoft.com/mapi/proptag/0x37010102";
private void Phishing_Load(object sender, RibbonUIEventArgs e)
{
outlookApp = new Outlook.Application();
inboxFolder = outlookApp.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
deleterFolder = outlookApp.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk);
mailItems = inboxFolder.Items;//.Restrict("[Unread]=true");
mailItems.Sort("[ReceivedTime]", true);
AddACategory();
items = inboxFolder.Items;
items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(CallFunction);
}
private void CallFunction(object data)
{
//move mail to another folder
}
private void mailProcessTrigger()
{
//mail process
}
}
}
Outlook對象模型中的項目不能在后台線程中使用,這將導致加載項不穩定,並可能導致加載項和Outlook崩潰。 您只能將Extended MAPI與C ++或Redemption一起使用,以運行多線程Outlook解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.