I was facing some problems regarding multi-tasks in VSTO, so i came up with this.
The first problem was understand that all calls into the Office OM will be serialized so while one thread is calling into Office, the remaining threads would be blocked from doing so because Office object model is not thread safe, but if you are calling into a component that is thread-safe, then COM doesn't need to get in the way and concurrency is allowed. The issue that you need to understand is how much time your threads will spend being blocked and whether that will invalidate the performance gain you are hoping for. If your tasks are truly self-contained (or call into Free Threaded components) then you won't blocked by COM if you run them on background threads.
As Geoff Darst from the Microsoft VSTO Team explain:
“It sounds like you might benefit from reviewing the COM threading documentation which can be found here: http://windowssdk.msdn.microsoft.com/en-us/library/ms693344.aspx. Hopefully, that will fill in any of the gaps in your reading of other threads.
It is possible to do multi-threading in VSTO solutions regardless of whether your threads interact with the Office OM. However, in the latter case, you need to implement IMessageFilter (the COM version, not System.Windows.Forms version) and you need to understand that all calls into the Office OM will be serialized so while one thread is calling into Office, the remaining threads would be blocked from doing so.
All of this is because the Office object model isn't thread safe. Since COM can't control the fact that a client might try to call a non-thread safe server with multiple threads, it does the next best thing which is to serialize the calls. On the other hand, if you are calling into a component that is thread-safe, then COM doesn't need to get in the way and concurrency is allowed.
As I said, it is always possible to use multiple threads in VSTO. The issue that you need to understand is how much time your threads will spend being blocked and whether that will invalidate the performance gain you are hoping for. If your tasks are truly self-contained (or call into Free Threaded components) then you won't blocked by COM if you run them on background threads.”
Geoff Darst, Microsoft VSTO Team, Source: VSTO Forum
Readings
Processes, Threads, and Apartments
http://msdn.microsoft.com/en-us/library/ms693344(VS.85).aspx
Choosing the Threading Model
Single-Threaded Apartments
Multithreaded Apartments
Single-Threaded and Multithreaded Communication
In-Process Server Threading Issues
Accessing Interfaces Across Apartments