| An interesting example |
|
I've recently put my hand on "Net and COM: The complete interoperability guide" by Adam Nathan. And it is an excellent book (much better than many other books by some other MS employees or MS Press). But I didn't like the idea of paying the full price for a three years old computer book so I waited until I found a copy with a 34% discount. In the end, I should have bought it earlier: it's that good. In my last entry, I mentioned that I had troubles with a multi VMR9 applications. This book didn't help me to fix the problem but I learned something which is worth pointing out. In chapter 6, the author has a section entitled "Callbacks from a COM object to .Net object" then he goes on to give a listing (Listing 6-3) of a VB.Net application that fails but its equivalent VB6 would be working correctly. He has to say this: "If you're expecting a managed callback method to be called on a certain thread, you're responsible for getting to the right thread yourself before calling the code with the thread affinity." Then in Listing 6-4, he fixes the problem using a ManualResetEvent object. (The download from the publisher web site contains these listings). The problem lies in the fact that many applications (like Windows Form Applications in VS) are implicitly STA but "no .Net components can assume that they will only be called on one thread". If you encounter some weird "InvalidCastException", you might want to study the code in Listing 6-4. |
| < Prev | Next > |
|---|











