Outlook Redemption (Redemption.dll) and Background Threading do not mix.

Outlook Redemption is a very nice library which allows access to many Outlook functions many of those not exposed via the Outlook object model. We are currently using Redemption in our application to add outlook appointments with reminders, pop email messages with pre-populated information, etc.

We wrapped the Redemption.dll into our own Singleton class and called it OutlookRedemption as you will see in the following code examples.

We have had a couple of situations where emailing from our application stops working or works intermittently and in both of those occurrences, the culprit was using the API in a back ground thread.

Recently while doing a round of application optimization, one of my colleagues decided to place the code that Authenticates into the ExchangeMailbox in a BackgroundWorker thread (highlighted in blue):

using (BackgroundWorker outlookLoader = new BackgroundWorker())
outlookLoader.DoWork +=new DoWorkEventHandler((s,b) => { OutlookRedemption.Instance.Logon(); });

We did a release and it took a little while to figure out that it was the background thread that was our problem. It did not make sense to put this operation in a background thread as this code is executing during application start up and it does not block the main thread but for a few milliseconds.

In order to resolve the problem, we simply got rid of all the code except for this:


Life was good again.

On another occasion we had a developer write this code:

using (BackgroundWorker outlookLoader = new BackgroundWorker())
string subject = “email subject”;
string to = “hlc@somedomain.com”;
// send the email
OutlookRedemption.Instance.PopEmail(subject, “email body”, to);

We did a release that included the code above and we started getting reports from our users that emailing out of our application was working sometimes and not working other times. We tested and verified with our own eyes that this was the case. A popular feature was working intermittently.

After getting rid of the background thread code and just letting the UI thread take care of popping the Outlook email the problem went away and life was good again:

OutlookRedemption.Instance.PopEmail(subject, “email body”, to);

The End.

Leave a Reply

Your email address will not be published. Required fields are marked *