.Net 4.0 Task and COM Objects

Add-in Express™ Support Service
That's what is more important than anything else

.Net 4.0 Task and COM Objects
COM and Task, do they work together? 
Keith Knight

Posts: 6
Joined: 2015-11-05

I'm looking to get some input on reading and writing to excel while inside a task. When we tried it in our application we noticed that on shutdown the addin would crash. If you weren't debugging and had the task manager open you would see werfault.exe pop up.

After digging around I found different post saying its possible, but it may also not work.

What we wanted to do is execute a Task handling reading from the active workbook, calls to the server, retrieving data, and rendering the sheets. While this task executes we were showing a wait dialog. It all worked great until you closed the application and you would see this crash.

After reading up on COM objects it sounds like Task and COM objects don't mix well. What I did then was remove everything out of the task and the crash went away. I was hoping to get a clearer answer here and make sure I'm not missing something. Is it safe to work with COM objects other than on the main thread and if so how? Any examples out there I could look at or does anyone know of any good reading material about it?
Posted 02 May, 2016 13:16:09 Top
Dmitry Kostochko

Add-in Express team

Posts: 2745
Joined: 2004-04-05
Hi Keith,

We don't recommend using additional threads for accessing the Office Object Model. Please have a look at the following blog post, I think it will be helpful:
On using threads in managed Office extensions
Posted 03 May, 2016 04:21:38 Top