How to make frequent COM object access calls from main thread in outlook addin.

Mar 19, 2013
Reaction score
Hi everyone,

I've recently started to explore MS office addin programming and my past experience and understanding of multi thread programming doesn't really seems to hold good in COM interop world. So I need help from experts in understanding this better.

I'm trying to write a Outlook AddIn and currently have multiple threads (timer threads) that gets launched from main UI thread and these timer threads needs to access the outlook store and access mail items and process them periodically. At first this seems to work fine.

However, at times I see some strange behavior (inconsistency in the data returned from outlook store). I then looked around web to figure out what is going on and I see that accessing COM objects from any threads apart from main thread is kind of not supported and can cause unexpected behavior and this possibly the reason why I see some strange behavior at times with my timer threads that access outlook store.

I also read that if there is need to access COM objects from other than main thread, they could register some kind of callback to UI and have UI access the com objects and pass the meta data to the thread which further can be processed.

Now, I cannot get rid of my timer threads as the main logic of my addIn is built into that which periodically checks for new mails/deleted mail/age of certain mails/etc.

Can someone throw some light on how I can still have my timer threads active and do the job its doing but COM access still happens on main/UI thread. How can I register callback and when and how will that call back is called ? how can I control the frequency at which the call back is called?

I'm using C# with Microsoft.Office.Interop.Outlook. .Net version is 4.0

Any help would be greatly appreciated. Thanks!

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question