Lessons Learned
When using a COM component created by a company known for their great cross platform statistics software, but not known for their Windows expertise, creates a COM component and sets the component’s threading model to both (STA and MTA models), don’t trust it. If said component was developed for and tested against VB 6.0 and you are using .Net, don’t trust that it can handle MTA, even though their sample .Net code never checks to make sure it is running on STA thread. And if you are really foolish enough to try to use this component in a multithreaded service, and it works “almost” all the time, but occasionally hangs all threads in the process, the first thing you should do is make sure all threads that call the component have their ApartmentState set to STA. Then make sure that the wrapper dll that you wrote to make life easier to deal with this crazy component checks the thread’s ApartmentState, and throws an error if it isn’t STA.
Life would be so much easier if I trusted my instincts instead of the documentation.
DonXML Demsak
The preceding blog entry has been syndicated from the DonXML Demsak’s All Things Techie Blog. Please post all comments on the original post, and not this one.