.Net Com Interop Create Slow Instance

I have a .net 4 application that uses Com Dll to send SMS messages. I used TlbImp to create the interop assembly, and this is what the application says.

When I try to instantiate this class, it takes a very long time (2-5 seconds).

I ran a performance profile in VS 2010, and the call that takes the longest is System.Activator.CreateInstance ().

I am looking for tips on how to debug or receive using Com Interop.

+4
source share
1 answer

What type of COM apartment is the stream on which you create the object?

If this is the main application thread and you do not note that the main entry point is with STAThreadAttribute , you will work in the MTA. If you use the attribute, your thread will be in the STA. For other threads, you can set the type of apartment using Thread.SetApartmentState before starting the thread.

If your COM object is registered in a different apartment model than you use, you will incur overhead for creating a new stream / apartment, an object created in this other apartment, and all messages that occur through the proxy / stubs instead of direct calls to COM -an object.

This may cause some performance issues.

+2
source

Source: https://habr.com/ru/post/1309471/


All Articles