This project has moved. For the latest updates, please go here.

Using NetOffice from different threads

Apr 20, 2012 at 8:17 AM

Hello,

first thanks for this great framework!

Is there a way to use NetOffice from different threads in the same application?

In this case in could happen that e. g. an Outlook folder is accessed from 2 threads at the same time.

I tested it and I get this ArgumentException ("An element with the same key already exists in the Dictionary."):
   at LateBindingApi.Core.Factory.CreateObjectFromComProxy(COMObject caller, Object comProxy)
   at NetOffice.OutlookApi._Application.GetNamespace(String type)
   [...]

Is that by design or is there a way to use this late binding API from different threads at the same time?

Best regards and thanks in advance for a short reply
Andreas 

Coordinator
Apr 20, 2012 at 8:46 AM
Edited Apr 20, 2012 at 8:47 AM

hmmmm....

what microsoft say is: COM Interop and Multithreading doesn works together but anyway. the error message sounds like we have a NetOffice issue here.
whats up behind? NetOffice stores meta infos about COM proxies in serveral dictionaries and re-use these infos in later calls for the same type. thats the reason for the performance in NetOffice ist not slower as earlybind calls. checkout the performance page: http://netoffice.codeplex.com/wikipage?title=Tec_Documentation_English_Performance what i have to do is to implement a thread safe mode with the C# lock keyword for critical sections. please gimme 2 days to implement these feature in the new NetOffice 1.5 release and please gimme a feedback that works for you.

Sebastian

Apr 20, 2012 at 8:51 AM
Edited Apr 20, 2012 at 8:52 AM

Hello Sebastian,

first thank you very much for your super-fast reply!

I would be very happy to test your thread safe implementation. Just post here when it's done and I'll test it immediately. 2 days sounds perfect. ;-)

Best regards and thanks again
Andreas

Coordinator
Apr 21, 2012 at 1:35 AM
Edited Apr 21, 2012 at 11:01 AM

hello andreas,

NetOffice 1.5 [Public Beta] contains bool Settings.EnableThreadSafe; now.
its true by default, no issues to use. why its true by default?
you help me to realize the problem with different threads dependent on events. if you register an event trigger, then the call comes from the office thread and all what you do here with office is in concurrence with your UI thread and NetOffice was not safe in this way before. thanks for your suggestion!

Sebastian

PS: the only reason for the beta flag in 1.5 is because the english documentation is not done.

Apr 21, 2012 at 7:56 AM

Hello Sebastian,

you're great, there are no issues with this new version anymore!

Best regards and thank you very much for your very fast support
Andreas