c# - Expose a class as STA COM -


I need to expose as a small C # class that I com. This tool, using the COM object, requires that I support STA. Is there anything special that I need to do with my COM object?

(I know about STAThread feature, but (unless I'm wrong) indicating that there is a thread of execution in .net STA is compatible, and demonstrates that My com object being compatible) need not be done for

There is no announcement here yet. Do you have anything to add to that?

  [ComVisible (right)] [ClassInterface (ClassInterfaceType.None)] [ComDefaultInterface (typeof (ITestClass1))] [Guid ( "093A3701-2C53 seeing need -4A31-97C5- 0F3C205E5B4C ")] public class Class1: ITestClass1 {..} [ComVisible (right)] [Guid (" 8D52F785-CDD8-4248-8AB7-97B8C19DE59B ")] public interface ITestClass1 {..}  < / div> 

advertises a COM server threading model that requires a registry entry called threading model. The single thread is default if the registry key is missing or when it is set to "apartment".

Regasm.exe sets this key "Both". This means that your server has been declared compatible with both STA threads and MTA threads. Some normally keep the .NET code in general, it supports threading but with the requirement that you have to take care of thread-security. This change is very strange, you have to write your own registration process and annotate it with [comrographic function] attribute.

The simple approach leaves the main set on both "both" and use the apartment status of your class constructor thread.GetartTrade (). GetApartmentState () If you throw an exception to tell the client exactly MTA that you do a lot of .NET classes do not support multi-threading.


Comments