COM Apartments

Whether you register a managed object using the Assembly Registration Tool (regasm) or you use one of the activation functions that do not require registration, like ClrCreateManagedInstance, a managed object behaves like a COM object with the Both threading model when called from an unmanaged client. In other words, the object will run on the same thread as its caller whether the calling thread resides within an STA or an MTA. The implication of this is that, if you are going to call a managed object from a multithreaded unmanaged client, you need to make sure that the managed object is thread safe. With COM, if you did not want to write thread synchronization code, you could simply specify that your object use an STA. With the .NET Framework, if multithreaded clients will use your managed class, you must write thread synchronization code using the System.Threading.Monitor or System.Threading.Mutex classes. You can also use the lock statement in C#, which simplifies the use of System.Threading.Monitor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.51.241