.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


Guest


Hello,

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: 2875
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:
https://www.add-in-express.com/creating-addins-blog/2010/11/04/threads-managed-office-extensions/
Posted 03 May, 2016 04:21:38 Top