Reputation: 11
Outlook UI thread is blocked when convert msg to eml using redemption
I'm developping an outlook addin to sync emails to server as eml. When the addin start, it will start a timer and check whether there's new emails and then upload them. For each email, I will convert them to eml using outlook Redemption. It works, but I found during the convertion, outlook UI would be blocked. I'm using following code to do the convertion. I also tried RDOSession.GetMessageFromID(mail.EntryID). It's the same. Anyone
public static string ToEmlFile(this Outlook.MailItem mail)
{
var msgFilename = Path.ChangeExtension(Path.GetTempFileName(), ".msg");
mail.SaveAs(msgFilename);
var item = RDOSessionMgr.GetInstance().GetMessageFromMsgFile(msgFilename);
var emlFilename = Path.ChangeExtension(Path.GetTempFileName(), ".eml");
item.SaveAs(emlFilename, Redemption.rdoSaveAsType.olRFC822);
return emlFilename;
}
public class RDOSessionMgr
{
private static Redemption.RDOSession _session;
static RDOSessionMgr()
{
_session = new Redemption.RDOSession();
_session.Logon(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
}
public static Redemption.RDOSession GetInstance()
{
return _session;
}
}
Upvotes: 0
Views: 206
Reputation: 66215
You should be able to run that code on a secondary thread - save the value of the Application.Session.MAPIOBJECT property in a global/class variable, then assign that value to the RDOSession.MAPIOBJECT property of the RDOSession object that you create on the secondary thread.
ON a related note, you can use that technique on the main thread as well - there is no reason to RDOSession.LOgon from inside an Outlook addin since you already have the MAPI session used by Outlook.
Upvotes: 1